home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / winftp.zip / WNFTPSRC.ZIP / WS_MAIN.C < prev    next >
C/C++ Source or Header  |  1994-01-07  |  78KB  |  2,129 lines

  1. //*****************************************************************************
  2. //*****************************************************************************
  3. //*****************************************************************************
  4. //*****************************************************************************
  5. //  Windows Sockets FTP Application
  6. //
  7. //  Based on the WS_FTP program written by: John A. Junod
  8. //  Internet: <junodj@gordon-emh2.army.mil>
  9. //
  10. //  This program executable and all source code is released into the public
  11. //  domain.  The primary purpose of this application was to learn what it
  12. //  takes to write a Window Sockets Application and this is NOT a full 
  13. //  implementation of an FTP client.
  14. //
  15. //  WINFTP written by:
  16. //      Santanu Lahiri       Internet: <slahiri@magnus.acs.ohio-state.edu>
  17. //
  18. //  Reworked most of the code in this module into a format similar to 
  19. //  the Microsoft Class Library Naming Convention.  Hopefully this will
  20. //  reduce the effort needed to convert it to an MSVC/C++ app if ever.
  21. //
  22. //  Added the Configuration Entry in the Connect dialog box to allow
  23. //  multiple configurations for the same host.  Also added the "Delete
  24. //  Config" option to delete unwanted configs.  Checking the "Save Config"
  25. //  will now save the current configuration or update an existing one.
  26. //
  27. //  Added the History option to the main window.  This control now tracks
  28. //  the directories being visited for ease of browsing.  This is a Drop-Down
  29. //  combo box where the list box shows the dirs.  Clicking on an entry in the
  30. //  list causes a CHDIR command to be executed.
  31. //
  32. //  Added a Refresh button to allow refreshing the Directory listings.  Next
  33. //  step is to add code to optionally suppress automatic listing of directories
  34. //  and allowing listing of specified file types.
  35. //
  36. //  Converted all Command buttons to simulated buttons to reduce resources.
  37. //  The remaining controls are the list boxes, combo boxes, radio
  38. //  buttons, and static text boxes.  This reduces #controls by about 22.
  39. //
  40. //  MODULE: WS_MAIN.C  (main window functions and some dialog boxes)
  41. //
  42. //*****************************************************************************
  43. //*****************************************************************************
  44. #include "ws_glob.h"
  45. #include "winftp.H"
  46. #include <stdio.h>
  47. #include <stdlib.h> 
  48. #include <direct.h>
  49. #include <dos.h>
  50.  
  51. #include <shellapi.h>
  52.  
  53. #define RB_SHOWCHECKS 8100
  54. #define EN_TEXTCHANGE 0x4000
  55.  
  56. int nView=0;
  57. int selects[256];
  58.  
  59. BOOL bDebugLog;
  60. static HBRUSH hbrGray1, hbrGray2;
  61.  
  62. FARPROC lpfnOldLocal,  lpfnNewLocal;
  63. FARPROC lpfnOldRemote, lpfnNewRemote;
  64.  
  65. LRESULT CALLBACK LocalDirProc  (HWND, UINT, WPARAM, LPARAM);
  66. LRESULT CALLBACK RemoteDirProc (HWND, UINT, WPARAM, LPARAM);
  67.  
  68. #ifndef USEASYNC
  69. SubProcessAsync (HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
  70. {
  71.   return(FALSE);
  72. }
  73. #endif
  74.  
  75. BOOL CALLBACK WS_DeleteFileProc (HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
  76.  
  77. //*****************************************************************************
  78. //  Main Program
  79. //*****************************************************************************
  80. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
  81. {
  82.   int        nRc;           // return value from Register Classes
  83.   int        nErr;
  84.  
  85. #ifdef WIN32
  86.   lstrcpy (szAppName, "WINFTP32");
  87. #else
  88.   lstrcpy (szAppName, "WINFTP16");
  89. #endif
  90.   
  91.   hInst = hInstance;
  92.   hbrGray1 = CreateSolidBrush (RGB (192,192,192));
  93.   hbrGray2 = CreateSolidBrush (RGB (128,128,128));
  94.  
  95.   if (!hPrevInstance)
  96.   {
  97.     if ((nRc = nCwRegisterClasses()) == -1)
  98.     {
  99.       MessageBox((HWND)NULL, "Window creation failed", NULL, MB_ICONEXCLAMATION);
  100.       return nRc;    
  101.     }
  102.   }
  103.  
  104.   if ((nErr=InitInstance (hInst))!=IDOK) return nErr;
  105.   if(strstr (lpszCmdLine, "auto")!=NULL) bAutoStart=TRUE;
  106.  
  107.   switch (nErr=WSAStartup( 0x0101, &WSAData))  // register with winsock tcp/ip API
  108.   {
  109.     case  0: nRc = ExecFTPApp (nCmdShow); break;
  110.     default: ReportWSError ("WSAStartup", nErr);            
  111.   }
  112.  
  113.   UnsetStatusLines();
  114.   unlink (szCurrentDir);
  115.   CwUnRegisterClasses();
  116.  
  117.   DeleteObject (hbrGray1);
  118.   DeleteObject (hbrGray2);
  119.   
  120.   return nRc;
  121. }
  122.  
  123. //*****************************************************************************
  124. //  Initialize this instance of the application
  125. //*****************************************************************************
  126. InitInstance (HINSTANCE hInst)
  127. {
  128.   long       nWndunits;       // window units for size and location
  129.   int        nWidth, nHeight; // resulting width and height for this window
  130.   
  131.   nWndunits = GetDialogBaseUnits();
  132.   nWndx = LOWORD (nWndunits);
  133.   nWndy = HIWORD (nWndunits);
  134.   nWidth = ((250 * nWndx) / 4);
  135.   nHeight = ((222 * nWndy) / 8);
  136.  
  137.   hWndMain = CreateWindow (szAppName, szDefaultHdr,  WS_OVERLAPPEDWINDOW,
  138.     CW_USEDEFAULT, CW_USEDEFAULT, nWidth, nHeight, (HWND) NULL, (HMENU) NULL, hInst,  NULL);
  139.  
  140.   if (hWndMain == (HWND) NULL)
  141.   {
  142.     MessageBox((HWND)NULL, "Error registering class", NULL, MB_ICONEXCLAMATION);
  143.     return IDCANCEL;
  144.   }
  145.   return IDOK;
  146. }
  147.  
  148. //*****************************************************************************
  149. //  Main message loop is in this routine
  150. //*****************************************************************************
  151. ExecFTPApp (int nCmdShow)
  152. {
  153.   MSG msg;
  154.   HWND hLocal;
  155.   HWND hRemote;
  156.   
  157.   GetLocalInfo();
  158.   hLocal  = GetDlgItem (hWndMain, EDT_LFILETYPE);
  159.   hRemote = GetDlgItem (hWndMain, EDT_RFILETYPE);
  160.   lpfnOldLocal  = (FARPROC) GetWindowLong (hLocal,  GWL_WNDPROC);
  161.   lpfnOldRemote = (FARPROC) GetWindowLong (hRemote, GWL_WNDPROC);
  162.   lpfnNewLocal  = (FARPROC) MakeProcInstance ((FARPROC) LocalDirProc,  hInst);
  163.   lpfnNewRemote = (FARPROC) MakeProcInstance ((FARPROC) RemoteDirProc,  hInst);
  164.   SetWindowLong (hLocal,  GWL_WNDPROC, (LONG) lpfnNewLocal);
  165.   SetWindowLong (hRemote, GWL_WNDPROC, (LONG) lpfnNewRemote);
  166.   
  167.   ShowWindow(hWndMain, nCmdShow);         // display main window
  168.   if (bAutoStart) PostMessage (hWndMain, WM_COMMAND, BTN_CONNECT, 0L);
  169.   while(GetMessage (&msg, (HWND) NULL, 0, 0))     // Until WM_QUIT message
  170.   {
  171.     TranslateMessage(&msg);
  172.     DispatchMessage(&msg);
  173.   }
  174.   WSACleanup();
  175.   ReleaseDisplayMem();
  176.   return msg.wParam;
  177. }
  178.  
  179. //*****************************************************************************
  180. //  Check and despatch messages as necessary
  181. //*****************************************************************************
  182. CheckMsgQueue (HWND hWnd)
  183. {
  184.   MSG Msg;
  185.   int i;
  186.   
  187.   for (i=0; i<10; i++)
  188.   {
  189.     if (!PeekMessage (&Msg, hWnd, 0, 0, PM_REMOVE)) return 0;
  190.     TranslateMessage (&Msg);
  191.     DispatchMessage (&Msg);
  192.   }
  193.   return 0;
  194. }
  195.  
  196. //*****************************************************************************
  197. // Clean up the files in the temp directory
  198. //*****************************************************************************
  199. void CleanupTempFiles (HWND hWnd)
  200. {
  201.   char szName[_MAX_PATH];
  202.   char szFile[_MAX_PATH];
  203.   int nMax, nI, nLen;
  204.   char *lp;
  205.   
  206. #ifdef WIN32
  207.   HANDLE hFile;
  208.   WIN32_FIND_DATA f;
  209. #else
  210.   struct _find_t f;
  211. #endif
  212.  
  213.   if (bRetain) return;
  214.   memset (szName, '\0', _MAX_PATH);
  215.   lstrcpy (szName, szTmpViewFile);
  216.   lp = strstr (szName, "%04d");
  217.   if (lp!=NULL)
  218.   {
  219.     lstrcpy (lp, "*.tmp");
  220.     lp = szTempDir;
  221.     if (lstrlen (szTempDir)>0) lp += lstrlen (szTempDir) - 1;
  222.     if (*lp=='\\') *lp = '\0';
  223.  
  224. #ifdef WIN32
  225.     while ((hFile=FindFirstFile (szName, &f))!=INVALID_HANDLE_VALUE)
  226.     {
  227.       wsprintf (szFile, "%s\\%s", szTempDir, f.cFileName);
  228.       unlink (szFile);
  229.       FindClose (hFile);
  230.     }
  231. #else
  232.     while (_dos_findfirst (szName, _A_NORMAL, &f)==0)
  233.     {
  234.       wsprintf (szFile, "%s\\%s", szTempDir, f.name);
  235.       unlink (szFile);
  236.     }
  237. #endif
  238.   }
  239.   nMax = (int) SendDlgItemMessage (hWnd, LST_DELFILES, LB_GETCOUNT, (WPARAM) 0, (LPARAM) 0L);
  240.   if ((nMax==0)||(nMax==LB_ERR)) return;
  241.   for (nI=0; nI<nMax; nI++)
  242.   {
  243.     nLen = (int) SendDlgItemMessage (hWndMain, LST_DELFILES, LB_GETTEXT, (WPARAM) nI, (LPARAM)(LPCSTR) szFile);
  244.     if (nLen>0) unlink (szFile);
  245.   }
  246. }
  247.  
  248. //*****************************************************************************
  249. //  If the current directory is not already in the list, add it in.
  250. //*****************************************************************************
  251. LPSTR FindViewerName (LPSTR lpName)
  252. {
  253.   char szBuf[_MAX_PATH];
  254.   int nI;
  255.   
  256.   lstrcpy (szBuf, lpName);
  257.   strupr (szBuf);
  258.   for (nI=0; nI<nViewNum; nI++)
  259.   {
  260.     if (strstr (szBuf, lpVuExt(nI))!=NULL) return (LPSTR) lpVuPgm(nI);
  261.   }
  262.   return szViewer;
  263. }
  264.  
  265. //*****************************************************************************
  266. //  If the current directory is not already in the list, add it in.
  267. //*****************************************************************************
  268. int FindViewerIndex (LPSTR lpName)
  269. {
  270.   char szBuf[_MAX_PATH];
  271.   int nI;
  272.   
  273.   lstrcpy (szBuf, lpName);
  274.   strupr (szBuf);
  275.   for (nI=0; nI<nViewNum; nI++)
  276.   {
  277.     if (strstr (szBuf, lpVuExt(nI))!=NULL) return nI;
  278.   }
  279.   return -1;
  280. }
  281.  
  282. //*****************************************************************************
  283. //  If the current directory is not already in the list, add it in.
  284. //*****************************************************************************
  285. AddDirToList (HWND hWnd, int nID, LPSTR lpDir)
  286. {
  287.   if (SendDlgItemMessage (hWnd, nID, CB_FINDSTRINGEXACT, (WPARAM) -1, (LPARAM)(LPCSTR) lpDir)==CB_ERR)
  288.      SendDlgItemMessage (hWnd, nID, CB_ADDSTRING, (WPARAM) 0, (LPARAM)(LPCSTR) lpDir);
  289.   return 0;
  290. }
  291.  
  292. //*****************************************************************************
  293. //  Directory selected from Local ComboBox dropdown list.  Switch to that dir.
  294. //  This is the "Recall History" function.
  295. //*****************************************************************************
  296. OnCmdLocalChangeDirLst (HWND hWnd)
  297. {
  298.   int nIndex;
  299.   char szMsgBuf[_MAX_PATH];
  300.  
  301.   if ((nIndex=(int) SendMessage (hLbxLDirLst, CB_GETCURSEL, 0, 0L))!=CB_ERR)
  302.   {
  303.     SendDlgItemMessage (hWnd, LST_LDIRLST, CB_GETLBTEXT, (WPARAM) nIndex, (LPARAM)(LPCSTR) szMsgBuf);
  304.     if (chdir (szMsgBuf)==0) GetLocalDirForWnd (hWnd);
  305.   }
  306.   return 0;
  307. }
  308.  
  309. //*****************************************************************************
  310. //  Change to selected local directory from the Directory/Drive list box
  311. //*****************************************************************************
  312. OnCmdLocalChangeDir (HWND hWnd)
  313. {
  314.   int nIndex;
  315.   FARPROC lpfnMsgProc; 
  316.   char szMsgBuf[_MAX_PATH];
  317.  
  318.   if ((nIndex=(int) SendMessage (hLbxLDir, LB_GETCURSEL, 0, 0L))!=LB_ERR)
  319.   {
  320.     SendMessage (hLbxLDir, LB_GETTEXT, nIndex, (LPARAM)(LPCSTR) szMsgBuf);
  321.     if (strncmp (szMsgBuf,"[-",2)==0) 
  322.     {
  323.       setdisk (szMsgBuf[2]-'a'+1);
  324.       GetLocalDirForWnd (hWnd);
  325.       return 0;
  326.     } 
  327.   }
  328.   switch (chdir (szMsgBuf))
  329.   {
  330.     case 0 : _getcwd (szMsgBuf, 80);
  331.              strlwr (szMsgBuf);
  332.              AddDirToList (hWnd, LST_LDIRLST, szMsgBuf);
  333.              GetLocalDirForWnd (hWnd); break;
  334.     default: lstrcpy (szDlgPrompt,"Enter local directory name:");
  335.              memset (szDlgEdit, '\0', sizeof (szDlgEdit));
  336.              lpfnMsgProc = MakeProcInstance ((FARPROC) WS_InputMsgProc, hInst);
  337.              DialogBox (hInst, (LPSTR) "DLG_INPUT", hWnd, lpfnMsgProc);
  338.              FreeProcInstance (lpfnMsgProc);
  339.              if (chdir(szDlgEdit)==0) 
  340.              {
  341.                _getcwd (szMsgBuf, 80);
  342.                strlwr (szMsgBuf);
  343.                AddDirToList (hWnd, LST_LDIRLST, szMsgBuf);
  344.                GetLocalDirForWnd(hWnd);  
  345.              }
  346.   }
  347.   return 0;
  348. }
  349.  
  350. //*****************************************************************************
  351. //*****************************************************************************
  352. OnCmdLocalToRemote (HWND hWnd)
  353. {
  354.   u_char szTmp[150];
  355.   char szLocalName[_MAX_PATH], szRemoteName[_MAX_PATH];
  356.   int nCount, nRC, nIndex;
  357.  
  358.   if (!bConnected) return 0;
  359.   bCancelXfer = FALSE;
  360.   bOpInProgress = TRUE;
  361.   nCount = (int) SendMessage (hLbxLFiles, LB_GETSELITEMS, 256, (LPARAM)(int far *) selects);
  362.   if (nCount>0 && nCount!=LB_ERR) 
  363.   {
  364.     
  365.     for (nIndex=0; (nIndex<nCount); nIndex++) 
  366.          SendMessage (hLbxLFiles, LB_SETSEL, (WPARAM) FALSE, MAKELPARAM (selects[nIndex], 0));
  367.     CreateXferWindow();
  368.     for (nIndex=0; (nIndex<nCount)&(!bCancelXfer); nIndex++) 
  369.     {
  370.       SendMessage (hLbxLFiles, LB_GETTEXT, selects[nIndex], (LPARAM)(LPCSTR) szLocalName);
  371.       SendMessage (hLbxLFiles, LB_SETSEL, (WPARAM) TRUE, MAKELPARAM (selects[nIndex], 0));
  372.       lstrcpy (szRemoteName, szLocalName);
  373.       if (bInteractive)
  374.       {
  375.         FARPROC lpfnMsgProc;
  376.         
  377.         wsprintf (szDlgPrompt, "Enter remote file name for %s:", szLocalName);
  378.         lstrcpy (szDlgEdit, szRemoteName);
  379.         lpfnMsgProc = MakeProcInstance ((FARPROC) WS_InputMsgProc, hInst);
  380.         DialogBox (hInst, (LPSTR) "DLG_INPUT", hWnd, lpfnMsgProc);
  381.         FreeProcInstance (lpfnMsgProc);
  382.         lstrcpy (szRemoteName, szDlgEdit);
  383.       }
  384.       wsprintf (szTmp, "Sending %s as %s (%u of %u)", szLocalName, szRemoteName, nIndex+1, nCount);
  385.       DoAddLine (szTmp);
  386.       wsprintf (szTmp, "STOR %s", szRemoteName);
  387.       nRC = SendFile (ctrl_socket, szTmp, szLocalName, fType);
  388.       SendMessage (hLbxLFiles, LB_SETSEL, (WPARAM) FALSE, MAKELPARAM (selects[nIndex], 0));
  389.     }
  390.     DeleteXferWindow();
  391.     GetRemoteDirForWnd(hWnd);
  392.   }
  393.   bOpInProgress = FALSE;
  394.   SendMessage (hTxtLBytes, WM_SETTEXT, (WPARAM) 0, (LPARAM)(LPCSTR) "");
  395.   return 0;
  396. }
  397.  
  398. //*****************************************************************************
  399. //*****************************************************************************
  400. OnCmdLocalMakeDir (HWND hWnd)
  401. {
  402.   FARPROC lpfnMsgProc;
  403.  
  404.   lstrcpy(szDlgPrompt, "Enter new local directory name:");
  405.   memset (szDlgEdit, '\0', sizeof (szDlgEdit));
  406.   lpfnMsgProc = MakeProcInstance ((FARPROC) WS_InputMsgProc, hInst);
  407.   DialogBox(hInst, (LPSTR) "DLG_INPUT", hWnd, lpfnMsgProc);
  408.   FreeProcInstance (lpfnMsgProc);
  409.   _mkdir (szDlgEdit);
  410.   GetLocalDirForWnd (hWnd);
  411.   return 0;
  412. }
  413.  
  414. //*****************************************************************************
  415. //*****************************************************************************
  416. OnCmdLocalRemoveDir (HWND hWnd)
  417. {
  418.   int nIndex;
  419.  
  420.   if ((nIndex=(int) SendMessage (hLbxLDir, LB_GETCURSEL, 0, 0L))!=LB_ERR)
  421.   {
  422.     SendMessage(hLbxLDir, LB_GETTEXT, nIndex, (LPARAM)(LPCSTR) szMsgBuf);
  423.     wsprintf (szString, "Are you sure you want to delete \"%s\"?", szMsgBuf);
  424.     if (MessageBox (hWnd, szString, "Verify Deletion", MB_YESNO)==IDYES)
  425.     {
  426.       if (_rmdir (szMsgBuf)==0) GetLocalDirForWnd (hWnd);
  427.     }
  428.   }
  429.   return 0;
  430. }
  431.  
  432. //*****************************************************************************
  433. //*****************************************************************************
  434. OnCmdLocalDeleteFile (HWND hWnd)
  435. {
  436.   int nIndex, nCount, nNum, nRC;
  437.   char szLocalName[_MAX_PATH];
  438.   BOOL bConfirm = TRUE;
  439.   FARPROC lpfnMsgProc;
  440.   
  441.   bCancelXfer = FALSE;
  442.   bOpInProgress = TRUE;
  443.   nCount = (int) SendMessage (hLbxLFiles, LB_GETSELITEMS, 256, (LPARAM) (int *) selects);
  444.   if (nCount>0 && nCount!=LB_ERR)
  445.   {
  446.     for (nIndex=0; (nIndex<nCount); nIndex++) 
  447.          SendMessage (hLbxLFiles, LB_SETSEL, (WPARAM) FALSE, MAKELPARAM (selects[nIndex], 0));
  448.     for (nIndex=0; (nIndex<nCount)&(!bCancelXfer); nIndex++) 
  449.     {
  450.       SendMessage(hLbxLFiles, LB_GETTEXT, nNum=selects[nIndex], (LPARAM)(LPCSTR) szLocalName);
  451.       SendMessage (hLbxLFiles, LB_SETSEL, (WPARAM) TRUE, MAKELPARAM (nNum, 0));
  452.       nRC = DLG_DELETE;
  453.       if (bConfirm)
  454.       {
  455.         lstrcpy (szDlgEdit, szLocalName);
  456.         lpfnMsgProc = MakeProcInstance ((FARPROC) WS_DeleteFileProc, hInst);
  457.         nRC = DialogBox (hInst, (LPSTR) "DLG_DELETEFILE", hWnd, lpfnMsgProc);
  458.         FreeProcInstance (lpfnMsgProc);
  459.       }
  460.       switch (nRC)
  461.       {
  462.         case DLG_NOTDELETE: break;
  463.         case IDCANCEL     : nIndex = nCount+1; break;
  464.         case DLG_DELETEALL: bConfirm = FALSE;
  465.         case DLG_DELETE   : _unlink (szLocalName); break;
  466.       }
  467.       SendMessage (hLbxLFiles, LB_SETSEL, (WPARAM) FALSE, MAKELPARAM (nNum, 0));
  468.     }
  469.     GetLocalDirForWnd (hWnd);
  470.   }
  471.   bOpInProgress = FALSE;
  472.   return 0;
  473. }
  474.  
  475. //*****************************************************************************
  476. //*****************************************************************************
  477. OnCmdLocalRenameFile (HWND hWnd)
  478. {
  479.   int nIndex;
  480.   FARPROC lpfnMsgProc;
  481.  
  482.   if ((nIndex=(int) SendMessage (hLbxLFiles, LB_GETCURSEL, 0, 0L))!=LB_ERR)
  483.   {
  484.     SendMessage (hLbxLFiles, LB_GETTEXT, nIndex, (LPARAM)(LPCSTR) szMsgBuf);
  485.     wsprintf (szDlgPrompt, "Enter new name for \"%s\":", szMsgBuf);
  486.     memset (szDlgEdit, '\0', sizeof (szDlgEdit));
  487.     lpfnMsgProc = MakeProcInstance ((FARPROC) WS_InputMsgProc, hInst);
  488.     DialogBox (hInst, (LPSTR) "DLG_INPUT", hWnd, lpfnMsgProc);
  489.     FreeProcInstance (lpfnMsgProc);
  490.     if (rename (szMsgBuf, szDlgEdit)==0) GetLocalDirForWnd (hWnd);
  491.   }
  492.   return 0;
  493. }
  494.  
  495. //*****************************************************************************
  496. //*****************************************************************************
  497. OnCmdLocalHistory (HWND hWnd)
  498. {  
  499.   return 0;
  500. }
  501.  
  502. //*****************************************************************************
  503. //*****************************************************************************
  504. LPSTR GetViewer (LPSTR lpLocalName, LPSTR lpVuPgm, LPSTR lpExt)
  505. {
  506.   static char szTmpViewer[_MAX_PATH];
  507.   char *lp;
  508.  
  509.   lp = strchr (lpLocalName, '.');
  510.   if (lp!=NULL)
  511.   {
  512.     strncpy (lpExt, ++lp, 4); 
  513.     GetProfileString ("Extensions", lpExt, "", szTmpViewer, sizeof (szTmpViewer)-5);
  514.     if (lstrlen (szTmpViewer) > 0) 
  515.     {
  516.       lp = strchr (szTmpViewer, '^');
  517.       if (lp!=NULL) *lp = '\0';
  518.       lpVuPgm = szTmpViewer;
  519.     }
  520.   }
  521.   return lpVuPgm;
  522. }
  523.  
  524. //*****************************************************************************
  525. //*****************************************************************************
  526. OnCmdLocalDisplay (HWND hWnd)
  527. {
  528.   char szLocalName[_MAX_PATH], szMsgBuf[_MAX_PATH], szDir[_MAX_PATH], *lpVuPgm;
  529.   char szExt[10];
  530.   int nIndex;
  531.  
  532.   if((nIndex=(int) SendMessage(hLbxLFiles, LB_GETCURSEL, 0, 0L))!=LB_ERR)
  533.   {
  534.     SendMessage (hTxtLDir, WM_GETTEXT, (WPARAM) sizeof (szDir)-1, (LPARAM)(LPCSTR) szDir);
  535.     SendMessage (hLbxLFiles, LB_GETTEXT, nIndex, (LPARAM)(LPCSTR) szLocalName);
  536.     lpVuPgm = FindViewerName (szLocalName);
  537.     if (lpVuPgm==szViewer) lpVuPgm = GetViewer (szLocalName, lpVuPgm, szExt);
  538.     nIndex = lstrlen (szDir)-1;
  539.     if (szDir[nIndex]=='\\') szDir[nIndex] = '\0';
  540.     wsprintf(szMsgBuf, "%s %s\\%s", lpVuPgm, szDir, szLocalName);
  541.     if ((nIndex=WinExec((LPCSTR) szMsgBuf, SW_SHOWNORMAL))<32)
  542.     {
  543.       wsprintf (szLocalName, "Error Code was %d", nIndex);
  544.       MessageBox (hWnd, szMsgBuf, szLocalName, MB_OK);
  545.     }
  546.   }
  547.   return 0;
  548. }
  549.  
  550. //*****************************************************************************
  551. //  Execute the Double Click command defined by current setting
  552. //*****************************************************************************
  553. OnCmdLButtonDblClkLocal (HWND hWnd)
  554. {
  555.   switch (bDblClkVu)
  556.   {
  557.     case FALSE: OnCmdLocalToRemote (hWnd); break;
  558.     default   : OnCmdLocalDisplay (hWnd); break;
  559.   }
  560.   return 0;
  561. }
  562.  
  563. //*****************************************************************************
  564. //*****************************************************************************
  565. OnCmdLocalRefresh (HWND hWnd)
  566. {  
  567.   GetLocalDirForWnd (hWnd);
  568.   return 0;
  569. }
  570.  
  571. //*****************************************************************************
  572. //*****************************************************************************
  573. OnCmdRemoteMakeDir (HWND hWnd)
  574. {
  575.   FARPROC lpfnMsgProc;
  576.   int nRC;
  577.  
  578.   if (!bConnected) return 0;
  579.   lstrcpy (szDlgPrompt, "Enter new remote directory name:");
  580.   memset (szDlgEdit, '\0', sizeof (szDlgEdit));
  581.   lpfnMsgProc = MakeProcInstance ((FARPROC) WS_InputMsgProc, hInst);
  582.   DialogBox (hInst, (LPSTR) "DLG_INPUT", hWnd, lpfnMsgProc);
  583.   FreeProcInstance (lpfnMsgProc);
  584.   nRC = DoMKD (ctrl_socket, szDlgEdit);
  585.   if (nRC==FTP_COMPLETE) GetRemoteDirForWnd (hWnd);
  586.   return 0;
  587. }
  588.  
  589. //*****************************************************************************
  590. //*****************************************************************************
  591. OnCmdRemoteRemoveDir (HWND hWnd)
  592. {
  593.   int nIndex, nRC;
  594.   char szMsgBuf[80];
  595.  
  596.   if (!bConnected) return 0;
  597.   if ((nIndex = (int) SendMessage (hLbxRDir, LB_GETCURSEL, 0, 0L))!=LB_ERR)
  598.   {
  599.     SendMessage (hLbxRDir, LB_GETTEXT, nIndex, (LPARAM)(LPCSTR) szMsgBuf);
  600.     wsprintf (szString, "Are you sure you want to delete \"%s\"?", szMsgBuf);
  601.     if (MessageBox (hWnd, szString, "Verify Deletion", MB_YESNO)==IDYES) 
  602.     {
  603.       nRC = DoRMD (ctrl_socket, szMsgBuf);
  604.       if (nRC==FTP_COMPLETE) GetRemoteDirForWnd (hWnd);
  605.     }
  606.   }
  607.   return 0;
  608. }
  609.  
  610. //*****************************************************************************
  611. //*****************************************************************************
  612. OnCmdRemoteDeleteFile (HWND hWnd)
  613. {
  614.   int nIndex, nCount, nRC;
  615.   char szRemoteName[80];
  616.   BOOL bConfirm = TRUE;
  617.   FARPROC lpfnMsgProc;
  618.   
  619.   bCancelXfer = FALSE;
  620.   bOpInProgress = TRUE;
  621.   nCount = (int) SendMessage (hLbxRFiles, LB_GETSELITEMS, 256, (LPARAM) (int *) selects);
  622.   if (nCount>0 && nCount!=LB_ERR)
  623.   {
  624.     for (nIndex=0; (nIndex<nCount); nIndex++) 
  625.          SendMessage (hLbxRFiles, LB_SETSEL, (WPARAM) FALSE, MAKELPARAM (selects[nIndex], 0));
  626.     for (nIndex=0; (nIndex<nCount)&(!bCancelXfer); nIndex++) 
  627.     {
  628.       SendMessage(hLbxRFiles, LB_GETTEXT, selects[nIndex], (LPARAM)(LPCSTR) szRemoteName);
  629.       SendMessage (hLbxRFiles, LB_SETSEL, (WPARAM) TRUE, MAKELPARAM (selects[nIndex], 0));
  630.       nRC = DLG_DELETE;
  631.       if (bConfirm)
  632.       {
  633.         lstrcpy (szDlgEdit, szRemoteName);
  634.         lpfnMsgProc = MakeProcInstance ((FARPROC) WS_DeleteFileProc, hInst);
  635.         nRC = DialogBox (hInst, (LPSTR) "DLG_DELETEFILE", hWnd, lpfnMsgProc);
  636.         FreeProcInstance (lpfnMsgProc);
  637.       }
  638.       switch (nRC)
  639.       {
  640.         case DLG_NOTDELETE: break;
  641.         case IDCANCEL     : nIndex = nCount+1; break;
  642.         case DLG_DELETEALL: bConfirm = FALSE;
  643.         case DLG_DELETE   : nRC = DoDELE (ctrl_socket, szRemoteName); break;
  644.       }
  645.       SendMessage (hLbxRFiles, LB_SETSEL, (WPARAM) FALSE, MAKELPARAM (selects[nIndex], 0));
  646.     }
  647.     GetRemoteDirForWnd (hWnd);
  648.   }
  649.   bOpInProgress = FALSE;
  650.   return 0;
  651. }
  652.  
  653. //*****************************************************************************
  654. //*****************************************************************************
  655. OnCmdRemoteRenameFile (HWND hWnd)
  656. {
  657.   int nIndex, nRC;
  658.   FARPROC lpfnMsgProc;
  659.   char szRemoteName[80];
  660.  
  661.   if (!bConnected) return 0;
  662.   if ((nIndex=(int) SendMessage (hLbxRFiles, LB_GETCURSEL, 0, 0L))!=LB_ERR)
  663.   {
  664.     SendMessage (hLbxRFiles, LB_GETTEXT, nIndex, (LPARAM)(LPCSTR) szRemoteName);
  665.     wsprintf (szDlgPrompt, "Enter new name for \"%s\":", szRemoteName);
  666.     memset (szDlgEdit, '\0', sizeof (szDlgEdit));
  667.     lpfnMsgProc = MakeProcInstance ((FARPROC) WS_InputMsgProc, hInst);
  668.     nRC=DialogBox(hInst, (LPSTR) "DLG_INPUT", hWnd, lpfnMsgProc);
  669.     FreeProcInstance (lpfnMsgProc);
  670.     if (nRC==IDOK)
  671.     {
  672.       nRC = command(ctrl_socket, "RNFR %s", szRemoteName);
  673.       if (nRC==FTP_CONTINUE) 
  674.       {
  675.         nRC=command (ctrl_socket, "RNTO %s", szDlgEdit);
  676.         if (nRC==FTP_COMPLETE) GetRemoteDirForWnd (hWnd);
  677.       }
  678.     }
  679.   }
  680.   return 0;
  681. }
  682.  
  683. //*****************************************************************************
  684. //*****************************************************************************
  685. OnCmdRemoteChangeDir (HWND hWnd)
  686. {
  687.   int nIndex, nRC;
  688.   FARPROC lpfnMsgProc;
  689.   char szMsgBuf[80];
  690.   
  691.   if (!bConnected) return 0;
  692.   if ((nIndex=(int) SendMessage (hLbxRDir, LB_GETCURSEL, 0, 0L))!=LB_ERR)
  693.   {
  694.     SendMessage (hLbxRDir, LB_GETTEXT, nIndex, (LPARAM)(LPCSTR) szMsgBuf);
  695.     nRC = DoCWD (ctrl_socket, szMsgBuf);
  696.     if (nRC==FTP_COMPLETE) 
  697.     {
  698.       GetRemoteDirForWnd (hWnd);
  699.     }
  700.   }
  701.   else
  702.   {
  703.     lstrcpy (szDlgPrompt, "Enter remote directory name:");
  704.     memset (szDlgEdit, '\0', sizeof (szDlgEdit));
  705.     lpfnMsgProc = MakeProcInstance ((FARPROC) WS_InputMsgProc, hInst);
  706.     nRC = DialogBox (hInst, (LPSTR) "DLG_INPUT", hWnd, lpfnMsgProc);
  707.     FreeProcInstance (lpfnMsgProc);
  708.     if (nRC==IDOK)
  709.     {
  710.       nRC = DoCWD ((SOCKET) ctrl_socket, szDlgEdit);
  711.       if (nRC==FTP_COMPLETE)
  712.       {
  713.         GetRemoteDirForWnd (hWnd);
  714.       }
  715.     }
  716.   }
  717.   return 0;
  718. }
  719.  
  720. //*****************************************************************************
  721. //*****************************************************************************
  722. OnCmdRemoteChangeDirLst (HWND hWnd)
  723. {
  724.   int nIndex, nRC;
  725.   char szMsgBuf[80];
  726.   
  727.   if (!bConnected) return 0;
  728.   if ((nIndex=(int) SendMessage (hLbxRDirLst, CB_GETCURSEL, 0, 0L))!=CB_ERR)
  729.   {
  730.     SendDlgItemMessage (hWnd, LST_RDIRLST, CB_GETLBTEXT, nIndex, (LPARAM)(LPCSTR) szMsgBuf);
  731.     nRC = DoCWD (ctrl_socket, szMsgBuf);
  732.     if (nRC==FTP_COMPLETE) 
  733.     {
  734.       GetRemoteDirForWnd (hWnd);
  735.     }
  736.   }
  737.   return 0;
  738. }
  739.  
  740. //*****************************************************************************
  741. //*****************************************************************************
  742. OnCmdRemoteToLocal (HWND hWnd)
  743. {
  744.   char szTmp[80];
  745.   char szRemoteName[80];
  746.   char szLocalName[80];
  747.   int nCount, nRC, nIndex;
  748.  
  749.   if (!bConnected) return 0;
  750.   bCancelXfer = FALSE;
  751.   bOpInProgress = TRUE;
  752.   nCount = (int) SendMessage (hLbxRFiles, LB_GETSELITEMS, 256, (LPARAM) (int far *) selects);
  753.   if (nCount>0 && nCount!=LB_ERR) 
  754.   {
  755.     memset (szRemoteName, '\0', 80);
  756.     memset (szLocalName,  '\0', 80);
  757.     for (nIndex=0; (nIndex<nCount); nIndex++) 
  758.          SendMessage (hLbxRFiles, LB_SETSEL, (WPARAM) FALSE, MAKELPARAM (selects[nIndex], 0));
  759.     for (nIndex=0; (nIndex<nCount)&(!bCancelXfer); nIndex++) 
  760.     {
  761.       SendMessage (hLbxRFiles, LB_GETTEXT, selects[nIndex], (LPARAM)(LPCSTR) szRemoteName);
  762.       SendMessage (hLbxRFiles, LB_SETSEL, (WPARAM) TRUE, MAKELPARAM (selects[nIndex], 0));
  763.       MakeLocalName (szLocalName, szRemoteName);
  764.       if (bInteractive)
  765.       { 
  766.         FARPROC lpfnMsgProc;
  767.         
  768.         wsprintf (szDlgPrompt, "Enter local file name for %s:", szRemoteName);
  769.         lstrcpy (szDlgEdit, szLocalName);
  770.         lpfnMsgProc = MakeProcInstance ((FARPROC) WS_InputMsgProc, hInst);
  771.         DialogBox (hInst, (LPSTR) "DLG_INPUT", hWnd, lpfnMsgProc);
  772.         FreeProcInstance (lpfnMsgProc);
  773.         lstrcpy (szLocalName, szDlgEdit);
  774.       }
  775.       DoPrintf ("receiving %s as %s (%u of %u)", szRemoteName, szLocalName, nIndex+1, nCount);
  776.       wsprintf (szTmp, "RETR %s", szRemoteName);
  777.       nRC = RetrieveFile ((SOCKET)ctrl_socket, (LPSTR) szTmp, (LPSTR) szLocalName, fType);
  778.       if (nRC==2) 
  779.       {
  780.         SendMessage (hLbxLFiles, LB_ADDSTRING, 0, (LPARAM)(LPCSTR) szRemoteName);
  781.         SendMessage (hLbxRFiles, LB_SETSEL, (WPARAM) FALSE, MAKELPARAM (selects[nIndex], 0));
  782.       }
  783.       else break;
  784.     }
  785.     DeleteXferWindow();
  786.     GetLocalDirForWnd (hWnd);
  787.   }
  788.   bOpInProgress = FALSE;
  789.   SendMessage (hTxtRBytes, WM_SETTEXT, (WPARAM) 0, (LPARAM)(LPCSTR) "");
  790.   return 0;
  791. }
  792.  
  793. //*****************************************************************************
  794. //*****************************************************************************
  795. OnCmdRemoteRefresh (HWND hWnd)
  796. {  
  797.   if (!bConnected) return 0;
  798.   GetRemoteDirForWnd (hWnd);
  799.   return 0;
  800. }
  801.  
  802. //*****************************************************************************
  803. //*****************************************************************************
  804. OnCmdRemoteHistory (HWND hWnd)
  805. {  
  806.   return 0;
  807. }
  808.  
  809. //*****************************************************************************
  810. //*****************************************************************************
  811. OnCmdRemoteDisplay (HWND hWnd)
  812. {
  813.   char szTmp[80], *lpVuExec, *lpViewDir;
  814.   char szRemoteName[80];
  815.   char szUniqViewFile[_MAX_PATH], szExt[_MAX_EXT];
  816.   int nIndex, nRC, nViewer, nLen;
  817.   char nXferType=TYPE_A;
  818.   
  819.   if (!bConnected) return 0;
  820.   if ((nIndex=(int) SendMessage (hLbxRFiles, LB_GETCURSEL, 0, 0L))!=LB_ERR)
  821.   {
  822.     SendMessage (hLbxRFiles, LB_GETTEXT, nIndex, (LPARAM)(LPCSTR) szRemoteName);
  823.     wsprintf (szTmp, "RETR %s", szRemoteName);
  824.     nViewer = FindViewerIndex (szRemoteName);
  825.     lpVuExec = (nViewer==-1) ? GetViewer (szRemoteName, szViewer, szExt) : lpVuPgm (nViewer);
  826.     nXferType = (nViewer==-1) ? (lpVuExec==szViewer?TYPE_A:TYPE_I) : GetViewTyp (nViewer);
  827.     switch (nViewer)
  828.     {
  829.       case -1: wsprintf (szUniqViewFile, szTmpViewFile, ++nView); break;
  830.       default: lpViewDir = lpVuDir (nViewer);
  831.                nLen = lpViewDir==NULL ? 0 : lstrlen (lpViewDir);
  832.                if ((lpViewDir==NULL) || (nLen==0))
  833.                {
  834.                   wsprintf (szUniqViewFile, szTmpViewFile, ++nView); 
  835.                }
  836.                else 
  837.                {
  838.                  lstrcpy (szUniqViewFile, lpViewDir);
  839.                  if (szUniqViewFile[nLen-1]!='\\') lstrcat (szUniqViewFile, "\\"), nLen++;
  840.                  wsprintf (szUniqViewFile+nLen, "WFTP%04d%s", nView++, lpVuExt(nViewer));
  841.                  SendDlgItemMessage (hWnd, LST_DELFILES, LB_ADDSTRING, (WPARAM) 0, (LPARAM)(LPCSTR) szUniqViewFile);
  842.                }
  843.     }
  844.     DoPrintf ("[1] Retrieve %s as %s", szRemoteName, szUniqViewFile);
  845.     bOpInProgress = TRUE;
  846.     nRC = RetrieveFile ((SOCKET) ctrl_socket, (LPSTR) szTmp, (LPSTR) szUniqViewFile, nXferType);
  847.     DeleteXferWindow();
  848.     bOpInProgress = FALSE;
  849.     if (nRC==2) 
  850.     {
  851.       DoPrintf ("[1] View %s as %s", szRemoteName, szUniqViewFile);
  852.       wsprintf (szString, "%s %s", lpVuExec, szUniqViewFile);
  853.       WinExec (szString, SW_SHOWNORMAL);
  854.       if ((!bRetain)&&(nView>1))
  855.       {
  856.         wsprintf (szUniqViewFile, szTmpViewFile, nView-1);
  857.         unlink (szUniqViewFile);
  858.       }
  859.     }
  860.   }
  861.   return 0;
  862. }
  863.  
  864. //*****************************************************************************
  865. //  Execute the Double Click command defined by current setting
  866. //*****************************************************************************
  867. OnCmdLButtonDblClkRemote (HWND hWnd)
  868. {
  869.   switch (bDblClkVu)
  870.   {
  871.     case FALSE: OnCmdRemoteToLocal (hWnd); break;
  872.     default   : OnCmdRemoteDisplay (hWnd); break;
  873.   }
  874.   return 0;
  875. }
  876.  
  877. //*****************************************************************************
  878. //*****************************************************************************
  879. OnShowTransferType (HWND hWnd)
  880. {
  881.   SendMessage (hRBascii,  BM_SETCHECK, fType==TYPE_A, 0L);
  882.   SendMessage (hRBbinary, BM_SETCHECK, fType==TYPE_I, 0L);
  883.   SendMessage (hRBl8,     BM_SETCHECK, fType==TYPE_L, 0L);
  884.   return 0;
  885. }
  886.  
  887. //*****************************************************************************
  888. //*****************************************************************************
  889. OnCmdConnectHost (HWND hWnd, WORD wNotifyCode)
  890. {
  891.   FARPROC lpfnMsgProc;
  892.   int nRC;
  893.   
  894.   if (ctrl_socket==INVALID_SOCKET) 
  895.   {
  896.     lpfnMsgProc = MakeProcInstance ((FARPROC) WS_HostMsgProc, hInst);
  897.     nRC = DialogBox (hInst, (LPSTR) "DLG_HOST", hWnd, lpfnMsgProc);
  898.     FreeProcInstance (lpfnMsgProc);
  899.     if (nRC) 
  900.     {
  901.       ctrl_socket = (SOCKET) DoConnect (szRemoteHost);
  902.       if (ctrl_socket!=INVALID_SOCKET)
  903.       {
  904.         RetrieveDirList (hWnd);
  905.         if (szInitDir[0]!=0) DoCWD (ctrl_socket, szInitDir);
  906.         if (wNotifyCode==BTN_CONNECT) GetRemoteDirForWnd (hWnd);
  907.         //if (szScript[0]!='\0') DoRunScript (hWnd, szScript);
  908.       }
  909.     }
  910.   }
  911.   else
  912.   {
  913.     DoAddLine ("Already connected");
  914.   }
  915.   return 0;
  916. }
  917.  
  918. //*****************************************************************************
  919. //*****************************************************************************
  920. OnCmdListHost (HWND hWnd)
  921. {
  922.   char szMsgBuf[_MAX_PATH+80];
  923.   
  924.   if (bConnected)
  925.   {
  926.     wsprintf (szMsgBuf, "%s %s", szViewer, szTmpDirFile);
  927.     WinExec (szMsgBuf, SW_SHOWNORMAL);
  928.   }
  929.   return 0;
  930. }
  931.  
  932. //*****************************************************************************
  933. //  Display the long dir listing
  934. //*****************************************************************************
  935. OnCmdNListHost (HWND hWnd, WORD wNotifyCode)
  936. {
  937.   char szMsgBuf[_MAX_PATH+80];
  938.   
  939.   if (wNotifyCode==CMD_NLST)
  940.   {
  941.     if(DoDirList ((SOCKET)ctrl_socket, "NLST")!=FTP_COMPLETE) return 0;
  942.   }
  943.   if (bConnected) 
  944.   {
  945.     wsprintf (szMsgBuf, "%s %s", szViewer, szCurrentDir);
  946.     WinExec (szMsgBuf, SW_SHOWNORMAL);
  947.   }
  948.   return 0;  
  949. }
  950.  
  951. //*****************************************************************************
  952. //*****************************************************************************
  953. OnCmdLogToFile (HWND hWnd, WORD wCtlID)
  954. {
  955.   HMENU hMenu = GetMenu (hWnd);
  956.   UINT nState = GetMenuState (hMenu, IDM_LOGTOFILE, MF_BYCOMMAND);
  957.                 
  958.   CheckMenuItem (hMenu, IDM_LOGTOFILE, nState=(nState==MF_CHECKED)?MF_UNCHECKED:MF_CHECKED);
  959.   nLogFlag = nState;
  960.   return 0;
  961. }
  962.  
  963. //*****************************************************************************
  964. //*****************************************************************************
  965. OnCmdLogFileName (HWND hWnd, WORD wCtlID)
  966. {
  967.   FARPROC lpfnMsgProc;
  968.   int nResult;
  969.  
  970.   lstrcpy (szDlgPrompt, "Enter Log File Name:");
  971.   strcpy (szDlgEdit, szLogFile);
  972.   lpfnMsgProc = MakeProcInstance ((FARPROC)WS_InputMsgProc, hInst);
  973.   nResult = DialogBox (hInst, (LPSTR) "DLG_INPUT", hWnd, lpfnMsgProc);
  974.   FreeProcInstance (lpfnMsgProc);
  975.   if (nResult==IDOK) strcpy (szLogFile, szDlgEdit);
  976.   return 0;
  977. }
  978.  
  979. //*****************************************************************************
  980. //*****************************************************************************
  981. OnCmdHelpHost (HWND hWnd)
  982. {
  983.   command ((SOCKET) ctrl_socket, "HELP");
  984.   return 0;
  985. }
  986.  
  987. //*****************************************************************************
  988. //*****************************************************************************
  989. OnCmdStatusHost (HWND hWnd)
  990.   FARPROC lpfnMsgProc;
  991.   
  992.   lpfnMsgProc = MakeProcInstance ((FARPROC) WS_StatMsgProc, hInst);
  993.   DialogBox (hInst, (LPSTR) "DLG_STATUS", hWnd, lpfnMsgProc);
  994.   FreeProcInstance (lpfnMsgProc);
  995.   SendMessage (hWnd, WM_COMMAND, RB_SHOWCHECKS, 0l);
  996.   return 0;
  997. }
  998.  
  999. //*****************************************************************************
  1000. //*****************************************************************************
  1001. OnCmdPWDHost (HWND hWnd)
  1002. {
  1003.   DoPWD ((SOCKET) ctrl_socket);
  1004.   return 0;
  1005. }
  1006.  
  1007. //*****************************************************************************
  1008. //*****************************************************************************
  1009. OnCmdDirOpHost (HWND hWnd, WORD wCtlID)
  1010. {
  1011.   FARPROC lpfnMsgProc;
  1012.   int nResult;
  1013.   
  1014.   lstrcpy(szDlgPrompt,"Enter remote directory name:");
  1015.   memset (szDlgEdit, '\0',sizeof (szDlgEdit));
  1016.   lpfnMsgProc=MakeProcInstance((FARPROC)WS_InputMsgProc,hInst);
  1017.   nResult = DialogBox(hInst,(LPSTR)"DLG_INPUT",hWnd,lpfnMsgProc);
  1018.   FreeProcInstance (lpfnMsgProc);
  1019.   if (nResult==IDOK) switch (wCtlID)
  1020.   {
  1021.     case CMD_RMD : DoRMD (ctrl_socket, szDlgEdit); break;
  1022.     case CMD_MKD : DoMKD (ctrl_socket, szDlgEdit); break;
  1023.   }
  1024.   return 0;
  1025. }
  1026.  
  1027. //*****************************************************************************
  1028. //*****************************************************************************
  1029. OnCmdGetFileHost (HWND hWnd)
  1030.   FARPROC lpfnMsgProc;
  1031.   int nResult;
  1032.   
  1033.   lstrcpy (szDlgPrompt, "Enter remote file name:");
  1034.   memset (szDlgEdit, '\0', sizeof (szDlgEdit));
  1035.   lpfnMsgProc = MakeProcInstance ((FARPROC) WS_InputMsgProc, hInst);
  1036.   nResult = DialogBox (hInst, (LPSTR) "DLG_INPUT", hWnd, lpfnMsgProc);
  1037.   FreeProcInstance (lpfnMsgProc);
  1038.   if (nResult==IDOK)
  1039.   {
  1040.     wsprintf (szDlgPrompt, "RETR %s", szDlgEdit);
  1041.     RetrieveFile (ctrl_socket, szDlgPrompt, szDlgEdit, fType);
  1042.   }
  1043.   return 0;
  1044. }
  1045.  
  1046. //*****************************************************************************
  1047. //*****************************************************************************
  1048. OnCmdPutFileHost (HWND hWnd)
  1049.   FARPROC lpfnMsgProc;
  1050.   int nResult;
  1051.   
  1052.   lstrcpy (szDlgPrompt, "Enter local file name:");
  1053.   memset (szDlgEdit, '\0', sizeof (szDlgEdit));
  1054.   lpfnMsgProc = MakeProcInstance ((FARPROC) WS_InputMsgProc, hInst);
  1055.   nResult = DialogBox (hInst, (LPSTR) "DLG_INPUT", hWnd, lpfnMsgProc);
  1056.   FreeProcInstance (lpfnMsgProc);
  1057.   if (nResult==IDOK)
  1058.   {
  1059.     wsprintf (szDlgPrompt, "STOR %s", szDlgEdit);
  1060.     SendFile (ctrl_socket, szDlgPrompt, szDlgEdit, fType);
  1061.   }
  1062.   return 0;
  1063. }
  1064.  
  1065. //*****************************************************************************
  1066. //*****************************************************************************
  1067. OnCmdQuoteHost (HWND hWnd)
  1068.   FARPROC lpfnMsgProc;
  1069.   int nResult;
  1070.   
  1071.   lstrcpy (szDlgPrompt, "Enter command for remote host:");
  1072.   memset (szDlgEdit, '\0', sizeof (szDlgEdit));
  1073.   lpfnMsgProc = MakeProcInstance ((FARPROC) WS_InputMsgProc, hInst);
  1074.   nResult = DialogBox(hInst, (LPSTR) "DLG_INPUT", hWnd, lpfnMsgProc);
  1075.   FreeProcInstance (lpfnMsgProc);
  1076.   if (nResult==IDOK) DoQUOTE ((SOCKET) ctrl_socket, szDlgEdit);
  1077.   return 0;
  1078. }
  1079.  
  1080. //*****************************************************************************
  1081. //*****************************************************************************
  1082. OnCmdGetCwdHost (HWND hWnd)    
  1083.   FARPROC lpfnMsgProc;
  1084.   int nResult;
  1085.  
  1086.   lstrcpy (szDlgPrompt, "Enter remote directory name:");
  1087.   memset (szDlgEdit, '\0', sizeof (szDlgEdit));
  1088.   lpfnMsgProc = MakeProcInstance ((FARPROC) WS_InputMsgProc, hInst);
  1089.   nResult = DialogBox (hInst, (LPSTR) "DLG_INPUT", hWnd, lpfnMsgProc);
  1090.   FreeProcInstance (lpfnMsgProc);
  1091.   if (nResult==IDOK) DoCWD ((SOCKET) ctrl_socket, szDlgEdit);
  1092.   return 0;
  1093. }
  1094.  
  1095. //*****************************************************************************
  1096. //*****************************************************************************
  1097. OnCmdFireWallSetup (HWND hWnd)    
  1098.   FARPROC lpfnMsgProc;
  1099.   int nResult;
  1100.  
  1101.   lpfnMsgProc = MakeProcInstance ((FARPROC) WS_FireWallSetupProc, hInst);
  1102.   nResult = DialogBox (hInst, (LPSTR) "DLG_FIREWALL", hWnd, lpfnMsgProc);
  1103.   FreeProcInstance (lpfnMsgProc);
  1104.   return 0;
  1105. }
  1106.  
  1107. //*****************************************************************************
  1108. //*****************************************************************************
  1109. OnCmdAbort (HWND hWnd)
  1110.   if (!bOpInProgress) return 0;
  1111.   //ForcePacket (ctrl_socket, "ABOR");
  1112.   bCancelXfer = TRUE;
  1113.   bAborted = TRUE;
  1114.   //if (WSAIsBlocking()) WSACancelBlockingCall();
  1115.   //ForceCommand (ctrl_socket, "ABOR");
  1116.   if (nTimerID!=-1)
  1117.   {
  1118.     KillTimer (hWndMain, nTimerID);
  1119.     nTimerID = -1;
  1120.   }
  1121.   DoAddLine("Operation aborted by user");    
  1122.   return 0;
  1123. }
  1124.  
  1125. //*****************************************************************************
  1126. //*****************************************************************************
  1127. OnCmdAbout (HWND hWnd)
  1128.   FARPROC lpfnMsgProc;
  1129.   
  1130.   lpfnMsgProc = MakeProcInstance ((FARPROC) WS_AboutMsgProc, hInst); 
  1131.   DialogBox (hInst, (LPSTR)"DLG_ABOUT", hWnd, lpfnMsgProc);
  1132.   FreeProcInstance (lpfnMsgProc);     
  1133.   return 0;
  1134. }
  1135.  
  1136. //*****************************************************************************
  1137. //*****************************************************************************
  1138. OnCmdShowDebug (HWND hWnd, WORD wCtrlID)
  1139. {
  1140.   HMENU hMenu = GetMenu (hWnd);
  1141.   UINT nState = GetMenuState (hMenu, IDM_SHOWDEBUG, MF_BYCOMMAND);
  1142.                 
  1143.   CheckMenuItem (hMenu, IDM_SHOWDEBUG, nState=(nState==MF_CHECKED)?MF_UNCHECKED:MF_CHECKED);
  1144.   ShowWindow (hWndDbg, nState==MF_CHECKED?SW_SHOWNORMAL : SW_HIDE);
  1145.   return 0;
  1146. }
  1147.  
  1148. //*****************************************************************************
  1149. //*****************************************************************************
  1150. OnCmdSaveDir (HWND hWnd, WORD wCtrlID)
  1151. {
  1152.   HMENU hMenu = GetMenu (hWnd);
  1153.   UINT nState = GetMenuState (hMenu, IDM_SAVEDIR, MF_BYCOMMAND);
  1154.                 
  1155.   CheckMenuItem (hMenu, IDM_SAVEDIR, nState=(nState==MF_CHECKED)?MF_UNCHECKED:MF_CHECKED);
  1156.   UpdateDirListOpt (hWnd, (BOOL) (nState==MF_CHECKED)?TRUE:FALSE);
  1157.   return 0;
  1158. }
  1159.  
  1160. //*****************************************************************************
  1161. //*****************************************************************************
  1162. OnCmdGetHostAddr (HWND hWnd, WORD wCtlID)
  1163. {
  1164.  
  1165. #ifdef WIN32
  1166.   DialogBox (hInst, (LPCTSTR)"DLG_FINDHOST", hWnd, (FARPROC) WS_FindHostProc);
  1167.   return 0;
  1168. #else
  1169.   FARPROC lpfnMsgProc;
  1170.   
  1171.   lpfnMsgProc = MakeProcInstance ((FARPROC) WS_FindHostProc, hInst); 
  1172.   DialogBox (hInst, (LPSTR)"DLG_FINDHOST", hWnd, lpfnMsgProc);
  1173.   FreeProcInstance (lpfnMsgProc);     
  1174.   return 0;
  1175. #endif
  1176.   
  1177. }
  1178.  
  1179. //*****************************************************************************
  1180. //*****************************************************************************
  1181. OnCmdSortByType (HWND hWnd, WORD wCtlID)
  1182. {
  1183.   HMENU hMenu = GetMenu (hWnd);
  1184.   LONG lStyle;
  1185.  
  1186.   if (wSortType==wCtlID) return 0;
  1187.   CheckMenuItem (hMenu, wSortType, MF_UNCHECKED);
  1188.   CheckMenuItem (hMenu, wSortType=wCtlID, MF_CHECKED);
  1189.   lStyle = GetWindowLong (hLbxRFiles, GWL_STYLE);
  1190.   switch (wSortType)
  1191.   {
  1192.     case IDM_SORTBYNAME: SetWindowLong (hLbxRFiles, GWL_STYLE, lStyle | LBS_SORT); break;
  1193.     default            : SetWindowLong (hLbxRFiles, GWL_STYLE, lStyle & ~LBS_SORT); break;
  1194.   }
  1195.   GetRemoteDirForWnd (hWnd);
  1196.   return 0;
  1197. }
  1198.  
  1199. //*****************************************************************************
  1200. //*****************************************************************************
  1201. OnCmdDownload (HWND hWnd, WORD wCtlID)
  1202. {
  1203. //  FARPROC lpfnMsgProc;
  1204.  
  1205. //  lpfnMsgProc = MakeProcInstance ((FARPROC) WS_DownloadProc, hInst); 
  1206. //  DialogBox (hInst, (LPSTR)"DLG_DOWNLOAD", hWnd, lpfnMsgProc);
  1207. //  FreeProcInstance (lpfnMsgProc);     
  1208.  
  1209. //  GetLocalDirForWnd (hWnd);
  1210.   return 0;
  1211. }
  1212.  
  1213. //*****************************************************************************
  1214. //*****************************************************************************
  1215. OnCmdLFileType (HWND hWnd, WORD wCode)
  1216. {
  1217.   char szBuf[20];
  1218.   
  1219.   if (wCode!=EN_TEXTCHANGE) return 0;
  1220.   memset (szBuf, '\0', 20);
  1221.   SendDlgItemMessage (hWnd, EDT_LFILETYPE, WM_GETTEXT, (WPARAM) 19, (LPARAM)(LPCSTR) szBuf);
  1222.   if (lstrcmpi (szBuf, szLFileType)==0) return 0;
  1223.   GetLocalDirForWnd (hWnd);
  1224.   return 0;  
  1225. }
  1226.  
  1227. //*****************************************************************************
  1228. //*****************************************************************************
  1229. OnCmdRFileType (HWND hWnd, WORD wCode)
  1230. {
  1231.   char szBuf[20];
  1232.   
  1233.   if (wCode!=EN_TEXTCHANGE) return 0;
  1234.   memset (szBuf, '\0', 20);
  1235.   SendDlgItemMessage (hWnd, EDT_RFILETYPE, WM_GETTEXT, (WPARAM) 19, (LPARAM)(LPCSTR) szBuf);
  1236.   if (lstrcmp (szBuf, szRFileType)==0) return 0;
  1237.   GetRemoteDirForWnd (hWnd);
  1238.   return 0;  
  1239. }
  1240.  
  1241. LPSTR szDisconnect = "You have a transfer in progress.\n"
  1242.                      "Disconnecting now may cause a GPF\n"
  1243.                      "Are you sure you wish to disconnect?";
  1244.  
  1245. //*****************************************************************************
  1246. //*****************************************************************************
  1247. OnCmdCloseOrExit (HWND hWnd, WPARAM wParam)
  1248. {
  1249.   if (bConnected)
  1250.   {
  1251.     if (bOpInProgress)
  1252.     {
  1253.       if (MessageBox (hWnd, szDisconnect, "Verify Disconnect", MB_YESNO)!=IDYES)
  1254.           return 0;
  1255.     }
  1256.     bAborted = TRUE;
  1257.     bCancelXfer = TRUE;
  1258.     if (data_socket!=INVALID_SOCKET) data_socket = DoClose (data_socket);
  1259.     if (listen_socket!=INVALID_SOCKET) listen_socket = DoClose (listen_socket);
  1260.     if (bConnected) DoDisconnect (ctrl_socket);  // Perform Shutdown
  1261.     if (ctrl_socket!=INVALID_SOCKET) 
  1262.     {
  1263.       ctrl_socket = DoClose (ctrl_socket);
  1264.       bConnected=FALSE;
  1265.     }
  1266.     SaveDirList (hWnd);
  1267.     SendDlgItemMessage (hWnd, LST_RDIRLST, CB_RESETCONTENT, 0, 0L);
  1268.     SetWindowText (hWnd, szDefaultHdr);
  1269.   }
  1270.   switch (wParam)
  1271.   {
  1272.     case IDM_EXIT:
  1273.     case BTN_EXIT: CleanupTempFiles (hWnd);
  1274.                    SendMessage (hWnd, WM_CLOSE, 0, 0L); break;
  1275.     default: GetRemoteDirForWnd (hWnd);
  1276.   }
  1277.   return 0;
  1278. }
  1279.  
  1280. //*****************************************************************************
  1281. //*****************************************************************************
  1282. LRESULT OnWmCmd (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1283. {
  1284.   WORD wNotifyCode;
  1285.   WORD wCtlID;
  1286.  
  1287. #ifdef WIN32
  1288.   wNotifyCode = HIWORD (wParam);
  1289.   wCtlID      = LOWORD (wParam);
  1290. #else
  1291.   wNotifyCode = HIWORD (lParam);
  1292.   wCtlID      = wParam;
  1293. #endif
  1294.  
  1295.   bAborted = FALSE;
  1296.   switch (wCtlID)
  1297.   {
  1298.     case BTN_CLOSE:
  1299.     case BTN_EXIT :
  1300.     case IDM_EXIT : OnCmdCloseOrExit (hWnd, wCtlID); return 0;
  1301.     default       : if (bCmdInProgress) return FALSE;
  1302.   }
  1303.   switch (wCtlID)
  1304.   {
  1305.     //*******************************************************
  1306.     // Local Button Functions and Dialog Boxes
  1307.     //*******************************************************
  1308.     case LST_LDIRS   : if (wNotifyCode==LBN_DBLCLK) OnCmdLocalChangeDir (hWnd); break;
  1309.     case LST_LDIRLST : if (wNotifyCode==CBN_SELCHANGE) OnCmdLocalChangeDirLst (hWnd); break;
  1310.     case LST_LFILES  : if (wNotifyCode==LBN_DBLCLK) OnCmdLButtonDblClkLocal (hWnd); break;
  1311.     case BTN_LCHANGE : OnCmdLocalChangeDir (hWnd); break;
  1312.     case BTN_LMKDIR  : OnCmdLocalMakeDir (hWnd); break;
  1313.     case BTN_LRMDIR  : OnCmdLocalRemoveDir (hWnd); break;
  1314.     case BTN_LDELETE : OnCmdLocalDeleteFile (hWnd); break;
  1315.     case BTN_LRENAME : OnCmdLocalRenameFile (hWnd); break;
  1316.     case BTN_LREFRESH: OnCmdLocalRefresh (hWnd); break;
  1317.     case BTN_LDISPLAY: OnCmdLocalDisplay (hWnd); break;
  1318.     case BTN_LHISTORY: OnCmdLocalHistory (hWnd); break;
  1319.     case BTN_LOCAL_TO_REMOTE: OnCmdLocalToRemote (hWnd); break;
  1320.  
  1321.     //*******************************************************
  1322.     // Remote Button Functions and Dialog Boxes
  1323.     //*******************************************************
  1324.     case LST_RDIRS   : if (wNotifyCode==LBN_DBLCLK) OnCmdRemoteChangeDir (hWnd); break;
  1325.     case LST_RDIRLST : if (wNotifyCode==CBN_SELCHANGE) OnCmdRemoteChangeDirLst (hWnd); break;
  1326.     case LST_RFILES  : if (wNotifyCode==LBN_DBLCLK) OnCmdLButtonDblClkRemote (hWnd); break;
  1327.     case BTN_RCHANGE : OnCmdRemoteChangeDir (hWnd);    break;
  1328.     case BTN_RMKDIR  : OnCmdRemoteMakeDir (hWnd); break;
  1329.     case BTN_RRMDIR  : OnCmdRemoteRemoveDir (hWnd); break;
  1330.     case BTN_RDELETE : OnCmdRemoteDeleteFile (hWnd); break;
  1331.     case BTN_RRENAME : OnCmdRemoteRenameFile (hWnd); break;
  1332.     case BTN_RREFRESH: OnCmdRemoteRefresh (hWnd); break;
  1333.     case BTN_RDISPLAY: OnCmdRemoteDisplay (hWnd); break;
  1334.     case BTN_RHISTORY: OnCmdRemoteHistory (hWnd); break;
  1335.     case BTN_REMOTE_TO_LOCAL: OnCmdRemoteToLocal (hWnd); break;
  1336.  
  1337.     case RB_ASCII : fType=TYPE_A; OnShowTransferType (hWnd); break;
  1338.     case RB_BINARY: fType=TYPE_I; OnShowTransferType (hWnd); break;
  1339.     case RB_L8    : fType=TYPE_L; OnShowTransferType (hWnd); break;
  1340.     case RB_SHOWCHECKS:           OnShowTransferType (hWnd); break;
  1341.  
  1342. //    case CMD_TYPE_I : fType=TYPE_I; break;
  1343. //    case CMD_TYPE_A : fType=TYPE_A; break;
  1344.     
  1345.     case BTN_LONG   : OnCmdNListHost (hWnd, wCtlID); break;
  1346.     case BTN_OPTION : OnCmdStatusHost (hWnd); break;
  1347.     case BTN_CONNECT: OnCmdConnectHost (hWnd, wCtlID); break;
  1348.     case BTN_ABORT  : OnCmdAbort (hWnd); break;
  1349.     case BTN_ABOUT  : OnCmdAbout (hWnd); break;
  1350.     
  1351.     case EDT_LFILETYPE: OnCmdLFileType (hWnd, wNotifyCode); break;
  1352.     case EDT_RFILETYPE: OnCmdRFileType (hWnd, wNotifyCode); break;
  1353.     
  1354.     case IDM_SHOWDEBUG  : OnCmdShowDebug (hWnd, wCtlID); break;
  1355.     case IDM_SAVEDIR    : OnCmdSaveDir (hWnd, wCtlID); break;
  1356.     case IDM_LOGTOFILE  : OnCmdLogToFile (hWnd, wCtlID); break;
  1357.     case IDM_LOGFILENAME: OnCmdLogFileName (hWnd, wCtlID); break;
  1358.     case IDM_HOSTADDR   : OnCmdGetHostAddr (hWnd, wCtlID); break;
  1359.     case IDM_HOSTLIST   : OnCmdDisplayHostList (hWnd, wCtlID, wNotifyCode); break;
  1360.     case IDM_DROPFILES  : OnCmdDropFiles (hWnd, (LPSTR *)lParam); break;
  1361.     case IDM_ZOOMINFO   : OnCmdZoomInfo (hWnd); break;
  1362.     case IDM_FIREWALL   : OnCmdFireWallSetup (hWnd); break;
  1363.     case IDM_SORTBYDATE : OnCmdSortByType (hWnd, wCtlID); break;
  1364.     case IDM_SORTBYNAME : OnCmdSortByType (hWnd, wCtlID); break;
  1365.     case IDM_DOWNLOAD   : OnCmdDownload (hWnd, wCtlID); break;
  1366.  
  1367.     case BTN_CLOSE  : OnCmdCloseOrExit (hWnd, wCtlID); break;
  1368.     case IDM_EXIT   : OnCmdCloseOrExit (hWnd, wCtlID); break;
  1369.     case IDM_ABOUT  : OnCmdAbout (hWnd); break;
  1370.     
  1371.     case CMD_CONNECT: OnCmdConnectHost (hWnd, wCtlID); break;
  1372.     case CMD_LIST   : OnCmdListHost (hWnd); break;
  1373.     case CMD_NLST   : OnCmdNListHost (hWnd, wCtlID); break;
  1374.     case CMD_HELP   : OnCmdHelpHost (hWnd); break;
  1375.     case CMD_PWD    : OnCmdPWDHost (hWnd); break;
  1376.     case CMD_RMD    : OnCmdDirOpHost (hWnd, wCtlID); break;
  1377.     case CMD_MKD    : OnCmdDirOpHost (hWnd, wCtlID); break;
  1378.     case CMD_RETR   : OnCmdGetFileHost (hWnd); break;
  1379.     case CMD_STOR   : OnCmdPutFileHost (hWnd); break;
  1380.     case CMD_QUOTE  : OnCmdQuoteHost (hWnd); break;
  1381.     case CMD_CWD    : OnCmdGetCwdHost (hWnd); break;
  1382.     
  1383.     default         : if (!SubProcessAsync (hWnd, Msg, wParam, lParam))
  1384.                           return DefWindowProc (hWnd, Msg, wParam, lParam);
  1385.   }
  1386.   return 0;
  1387. }
  1388.  
  1389. //*****************************************************************************
  1390. //*****************************************************************************
  1391. LRESULT OnSetCursor (HWND hWnd,UINT Msg,WPARAM wParam, LPARAM lParam)
  1392. {
  1393.   switch (bCmdInProgress)
  1394.   {
  1395.     case TRUE: SetCursor (hWaitCursor); return TRUE;
  1396.     default  : return (LRESULT) DefWindowProc (hWnd, Msg, wParam, lParam); 
  1397.   }
  1398. }
  1399.  
  1400. //*****************************************************************************
  1401. //*****************************************************************************
  1402. LRESULT OnPaint (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1403. {
  1404.   DoMainPaint (hWnd); 
  1405.   return 0;
  1406. }
  1407.  
  1408. int nBtnNum=-1;
  1409. int nListView=0;
  1410.  
  1411. //*****************************************************************************
  1412. //*****************************************************************************
  1413. LRESULT OnRButtonDown (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1414. {
  1415.   if (nListView) return (LRESULT) 0;
  1416.   ShowWindow (GetDlgItem (hWnd, LST_DELFILES), SW_SHOWNORMAL);
  1417.   nListView = 1;
  1418.   return (LRESULT) NULL;
  1419. }
  1420.  
  1421. //*****************************************************************************
  1422. //*****************************************************************************
  1423. LRESULT OnRButtonUp (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1424. {
  1425.   if (!nListView) return (LRESULT) 0;
  1426.   ShowWindow (GetDlgItem (hWnd, LST_DELFILES), SW_HIDE);
  1427.   nListView = 0;
  1428.   return (LRESULT) NULL;
  1429. }
  1430.  
  1431. //*****************************************************************************
  1432. //*****************************************************************************
  1433. LRESULT OnLButtonDown (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1434. {
  1435.   int nBtn;
  1436.   //HWND hWndFocus, hFile;
  1437.   
  1438.   if ((nBtn=FindButtonClicked (LOWORD (lParam), HIWORD (lParam)))==-1) return (LRESULT) 0;
  1439.   if (!GetButtonEnabledStatus (nBtn)) return (LRESULT) 0;
  1440.   if (SetButtonStatus (nBtn, 1)) return (LRESULT) 0;
  1441.   DoPaintButton (hWnd, nBtnNum=nBtn, 1);
  1442.   return (LRESULT) NULL;
  1443. }
  1444.  
  1445. //*****************************************************************************
  1446. //*****************************************************************************
  1447. LRESULT OnLButtonUp (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1448. {
  1449.   int nBtn, nID;
  1450.   
  1451.   if (nBtnNum==-1) return (LRESULT) NULL;
  1452.   if ((nBtn=FindButtonClicked (LOWORD (lParam), HIWORD (lParam)))==-1) return (LRESULT) 0;
  1453.   if (!GetButtonEnabledStatus (nBtn)) return (LRESULT) 0;
  1454.   if (nBtn!=nBtnNum) return (LRESULT) NULL;
  1455.   if (!SetButtonStatus (nBtn, 0)) return (LRESULT) NULL;
  1456.   switch (nID=GetButtonID (nBtn))
  1457.   {
  1458.     case BTN_ABORT: OnCmdAbort (hWnd); break;
  1459.  
  1460. #ifdef WIN32
  1461.     default       : PostMessage (hWnd, WM_COMMAND, MAKEWPARAM (nID, WM_LBUTTONUP), 0L); break;
  1462. #else
  1463.     default       : PostMessage (hWnd, WM_COMMAND, (WPARAM) nID, 0L); break;
  1464. #endif
  1465.   }
  1466.   DoPaintButton (hWnd, nBtn, 0);
  1467.   nBtnNum = -1;
  1468.   return (LRESULT) NULL;
  1469. }
  1470.  
  1471. //*****************************************************************************
  1472. //*****************************************************************************
  1473. LRESULT OnMouseMove (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1474. {
  1475.   int nBtn;
  1476.   
  1477.   if ((nBtnNum==-1) || !(wParam & MK_LBUTTON)) return (LRESULT) NULL;
  1478.   if ((nBtn=FindButtonClicked (LOWORD (lParam), HIWORD (lParam)))==nBtnNum) return (LRESULT) 0;
  1479.   if (nBtnNum==-1) return (LRESULT) NULL;
  1480.   if (!SetButtonStatus (nBtnNum, 0)) return (LRESULT) NULL;
  1481.   DoPaintButton (hWnd, nBtnNum, 0);
  1482.   nBtnNum = -1;
  1483.   return (LRESULT) NULL;
  1484. }
  1485.  
  1486. //*****************************************************************************
  1487. //*****************************************************************************
  1488. LRESULT OnVScroll (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1489. {
  1490.   switch(wParam) 
  1491.   {
  1492.     case SB_LINEUP  : ScrollStatus (hWnd, -1); break;
  1493.     case SB_LINEDOWN: ScrollStatus (hWnd, 1) ; break;
  1494.   }
  1495.   return DefWindowProc(hWnd, Msg, wParam, lParam);
  1496. }
  1497.  
  1498. #ifdef WIN32
  1499.  
  1500. //*****************************************************************************
  1501. //*****************************************************************************
  1502. LRESULT OnCtlColorBtn (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1503. {
  1504.   if (lParam==(LPARAM) hRBascii || lParam==(LPARAM) hRBbinary || lParam==(LPARAM) hRBl8) 
  1505.   {
  1506.     SelectObject ((HDC)wParam, GetStockObject (ANSI_VAR_FONT));
  1507.     SetBkColor ((HDC) wParam, RGB (192,192,192));
  1508.     return (LRESULT) hbrGray1;
  1509.   }
  1510.   return (LRESULT) NULL;
  1511. }
  1512.  
  1513.  
  1514. //*****************************************************************************
  1515. //*****************************************************************************
  1516. LRESULT OnCtlColorStatic (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1517. {
  1518.   SelectObject ((HDC)wParam, GetStockObject (ANSI_VAR_FONT));
  1519.   SetBkColor ((HDC) wParam, RGB (192,192,192));
  1520.   return (LRESULT) hbrGray1;
  1521. }
  1522.  
  1523. #else
  1524.  
  1525. //*****************************************************************************
  1526. //*****************************************************************************
  1527. LRESULT OnCtlColor (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1528. {
  1529.   switch (HIWORD(lParam)) 
  1530.   {
  1531.     case CTLCOLOR_BTN: if (!(LOWORD(lParam)==hRBascii || LOWORD(lParam)==hRBbinary || LOWORD(lParam)==hRBl8)) 
  1532.       {
  1533.         SelectObject ((HDC)wParam, GetStockObject(ANSI_VAR_FONT));
  1534.         return (LRESULT) NULL;
  1535.       }
  1536.     case CTLCOLOR_STATIC:
  1537.                 SelectObject ((HDC)wParam, GetStockObject (ANSI_VAR_FONT));
  1538.                 SetBkColor ((HDC) wParam, RGB (192,192,192));
  1539.                 return (LRESULT) hbrGray1;
  1540.   }
  1541.   return (LRESULT) NULL;
  1542. }
  1543.  
  1544. #endif
  1545.  
  1546. //*****************************************************************************
  1547. //*****************************************************************************
  1548. LRESULT OnClose (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1549. {
  1550.   if (hWnd == hWndMain) 
  1551.   {
  1552.     if (data_socket!=INVALID_SOCKET) data_socket = DoClose (data_socket);
  1553.     if (listen_socket!=INVALID_SOCKET) listen_socket = DoClose (data_socket);
  1554.     if (ctrl_socket!=INVALID_SOCKET) ctrl_socket = DoClose (ctrl_socket);
  1555.     DragAcceptFiles (hWnd, FALSE);
  1556.     DestroyWindow (hWnd);
  1557.     SaveUserInfo();
  1558.     PostQuitMessage (0);  // Quit the application
  1559.   }
  1560.   else
  1561.   {
  1562.     DestroyWindow (hWnd);
  1563.   }
  1564.   return 0;
  1565. }
  1566.  
  1567. //*****************************************************************************
  1568. //*****************************************************************************
  1569. LRESULT OnSetFocus (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1570. {
  1571.   SetFocus (GetDlgItem (hWnd, EDT_LFILETYPE));
  1572.   return 0;
  1573. }
  1574.  
  1575. //*****************************************************************************
  1576. //*****************************************************************************
  1577. LRESULT OnKillFocus (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1578. {
  1579.   
  1580.   return 0;
  1581. }
  1582.  
  1583. //*****************************************************************************
  1584. //*****************************************************************************
  1585. LRESULT OnDragDropFile (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1586. {
  1587.   UINT uiFiles, uiNum;
  1588.   LPSTR *lpPtr;
  1589.  
  1590. #ifdef WIN32
  1591. #define  IDDROPNUM  0xFFFFFFFF
  1592. #else
  1593. #define  IDDROPNUM  0xFFFF
  1594. #endif
  1595.  
  1596.   uiFiles = DragQueryFile ((HANDLE) wParam, IDDROPNUM, (LPSTR) NULL, 0);
  1597.   if (uiFiles==0) return 0;
  1598.   
  1599.   lpPtr = (LPSTR *) GlobalAllocPtr (GHND, (uiFiles+2)*sizeof (LPSTR));
  1600.   if (lpPtr!=NULL) 
  1601.   {
  1602.     for (uiNum = 0; uiNum < uiFiles; uiNum++) 
  1603.     {
  1604.       lpPtr[uiNum] = (LPSTR) GlobalAllocPtr (GHND, _MAX_PATH);
  1605.       if (lpPtr[uiNum]!=NULL) DragQueryFile ((HANDLE) wParam, uiNum, lpPtr[uiNum], _MAX_PATH);
  1606.     }
  1607.     lpPtr[uiNum] = (LPSTR) NULL;
  1608.   }
  1609.   DragFinish ((HANDLE) wParam);
  1610.   PostMessage (hWnd, WM_COMMAND, (WPARAM) IDM_DROPFILES, (LPARAM) lpPtr);
  1611.   return 0;
  1612. }
  1613.  
  1614.  
  1615. //*****************************************************************************
  1616. //*****************************************************************************
  1617. LRESULT OnCreate (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1618. {
  1619.   hStdCursor=LoadCursor((HINSTANCE)NULL,IDC_ARROW);
  1620.   hWaitCursor=LoadCursor((HINSTANCE)NULL,IDC_WAIT);
  1621.   LoadUserInfo();
  1622.   CreateDebugWindow(hWnd,hInst);
  1623.   CreateSubWindows(hWnd,hInst);
  1624.   GetLocalDirForWnd(hWnd);
  1625.   GetRemoteDirForWnd(hWnd);
  1626.   SendMessage(hWnd,WM_COMMAND,RB_SHOWCHECKS,0L);
  1627.   DragAcceptFiles (hWnd, TRUE);
  1628.   CheckMenuItem (GetMenu (hWnd), IDM_LOGTOFILE, nLogFlag);
  1629.   CheckMenuItem (GetMenu (hWnd), wSortType=IDM_SORTBYNAME, MF_CHECKED);
  1630.   return 0;
  1631. }
  1632.  
  1633. //*****************************************************************************
  1634. //*****************************************************************************
  1635. LRESULT OnTimer (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1636. {
  1637.   if ((int) wParam==10)
  1638.   {
  1639.     KillTimer (hWndMain, 10);
  1640.     nTimerID = -1;
  1641.     if(WSAIsBlocking()) 
  1642.     {
  1643.       DoAddLine("Timer cancelled blocking call");    
  1644.       bAborted=TRUE;
  1645.       WSACancelBlockingCall();
  1646.     }
  1647.   }
  1648.   return 0;
  1649. }
  1650.  
  1651. //*****************************************************************************
  1652. //*****************************************************************************
  1653. LRESULT OnParentNotify (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1654. {
  1655.   static WORD wChildID=0;
  1656.   WORD wTmpID;
  1657.   int nSel, nI;
  1658.   
  1659.   if (wParam!=WM_LBUTTONDOWN) return DefWindowProc (hWnd, Msg, wParam, lParam);
  1660.   wTmpID = GetChildWindowID (lParam);
  1661.   if ((wChildID==wTmpID)||(wTmpID==0)) return 0L;
  1662.   
  1663.   switch (wChildID)
  1664.   {
  1665.     case LST_LDIRS   : 
  1666.     case LST_RDIRS   : SendDlgItemMessage (hWnd, wChildID, LB_SETCURSEL, (WPARAM) -1, 0L); break;
  1667.  
  1668.     case LST_LFILES  : 
  1669.     case LST_RFILES  : nSel = (int) SendDlgItemMessage (hWnd, wChildID, LB_GETSELITEMS, 256, (LPARAM) (int far *) selects);
  1670.                        if (nSel>0 && nSel!=LB_ERR) 
  1671.                        {
  1672.                          for (nI=0; nI<nSel; nI++) 
  1673.                            SendDlgItemMessage (hWnd, wChildID, LB_SETSEL, (WPARAM) FALSE, MAKELPARAM (selects[nI], 0));
  1674.                        }
  1675.                        break;
  1676.     default          : wChildID = wTmpID;
  1677.                        return DefWindowProc (hWnd, Msg, wParam, lParam);
  1678.   }
  1679.   wChildID = wTmpID;
  1680.   return 0L;
  1681. }
  1682.  
  1683. /************************************************************************/
  1684. /* Main Window Procedure                                                */
  1685. /* This procedure provides service routines for the Windows events      */
  1686. /* (messages) that Windows sends to the window, as well as the user     */
  1687. /* initiated events (messages) that are generated when the user selects */
  1688. /* the action bar and pulldown menu controls or the corresponding       */
  1689. /* keyboard accelerators.                                               */
  1690. /************************************************************************/
  1691. LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
  1692. {
  1693.   switch (Msg)
  1694.   {
  1695.     case WM_CREATE      : return OnCreate (hWnd, Msg, wParam, lParam); break;
  1696.     case WM_TIMER       : return OnTimer  (hWnd, Msg, wParam, lParam); break;
  1697.     case WM_COMMAND     : return OnWmCmd  (hWnd, Msg, wParam, lParam); break;
  1698.     case WM_SETCURSOR   : return OnSetCursor (hWnd, Msg, wParam, lParam); break;
  1699.     case WM_PAINT       : return OnPaint  (hWnd, Msg, wParam, lParam); break;
  1700.     case WM_LBUTTONDOWN : return OnLButtonDown (hWnd, Msg, wParam, lParam); break;
  1701.     case WM_LBUTTONUP   : return OnLButtonUp (hWnd, Msg, wParam, lParam); break;
  1702.     case WM_MOUSEMOVE   : return OnMouseMove (hWnd, Msg, wParam, lParam); break;
  1703.     case WM_VSCROLL     : return OnVScroll (hWnd, Msg, wParam, lParam); break;
  1704.     case WM_KILLFOCUS   : return OnKillFocus (hWnd, Msg, wParam, lParam); break;
  1705.     case WM_SETFOCUS    : return OnSetFocus (hWnd, Msg, wParam, lParam); break;
  1706.     case WM_PARENTNOTIFY: return OnParentNotify (hWnd, Msg, wParam, lParam); break;
  1707.     case WM_DROPFILES   : return OnDragDropFile (hWnd, Msg, wParam, lParam); break;
  1708.     case WM_CLOSE       : return OnClose  (hWnd, Msg, wParam, lParam); break;
  1709.  
  1710.     //case WM_RBUTTONDOWN : return OnRButtonDown (hWnd, Msg, wParam, lParam); break;
  1711.     //case WM_RBUTTONUP   : return OnRButtonUp (hWnd, Msg, wParam, lParam); break;
  1712.  
  1713. #ifdef WIN32
  1714.     case WM_CTLCOLORBTN   : return OnCtlColorBtn (hWnd, Msg, wParam, lParam); break; 
  1715.     case WM_CTLCOLORSTATIC: return OnCtlColorStatic (hWnd, Msg, wParam, lParam); break;
  1716. #else
  1717.     case WM_CTLCOLOR    : return OnCtlColor (hWnd, Msg, wParam, lParam); break;
  1718. #endif
  1719.     
  1720.     default             : return DefWindowProc (hWnd, Msg, wParam, lParam);
  1721.   }
  1722.   return 0L;
  1723. }
  1724.  
  1725. /************************************************************************/
  1726. /************************************************************************/
  1727. void CreateTempFileNames (LPSTR szTempDir)
  1728. {
  1729.   char szDir[100], *lp;
  1730.   
  1731.   lstrcpy (szDir, szTempDir);
  1732.   lp = szDir;
  1733.   if (lstrlen (lp)>0) lp += lstrlen (lp)-1;
  1734.   if (*lp=='\\') *lp='\0';
  1735.   wsprintf (szTmpDirFile,  "%s\\%s", szDir, szTmpDirFileName);
  1736.   wsprintf (szTmpViewFile, "%s\\%s", szDir, szTmpViewFileName);
  1737. }
  1738.  
  1739. /************************************************************************/
  1740. /* Misc Dialog Window Procedures                                        */
  1741. /************************************************************************/
  1742. BOOL CALLBACK WS_AboutMsgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
  1743.   switch (Msg)
  1744.   {
  1745.     case WM_INITDIALOG: 
  1746.       {
  1747.         char szVer[80];
  1748.         LPSTR szStamp = __DATE__;
  1749.  
  1750.         wsprintf (szVer, "Version %s", szStamp);
  1751.         SetWindowText (GetDlgItem (hDlg, IDC_VERSION), szVer);
  1752.         cwCenter (hDlg, 0); 
  1753.       } break;
  1754.     case WM_CLOSE     : PostMessage (hDlg, WM_COMMAND, IDCANCEL, 0L); break;
  1755.     case WM_COMMAND   : switch (wParam)
  1756.       {
  1757.         case IDOK     : EndDialog(hDlg, TRUE); return TRUE;
  1758.         case IDCANCEL : EndDialog(hDlg, FALSE); return TRUE;
  1759.         default       : return TRUE;
  1760.       }
  1761.     default: return FALSE;
  1762.   }
  1763. }
  1764.  
  1765. /************************************************************************/
  1766. /************************************************************************/
  1767. BOOL CALLBACK WS_FireWallSetupProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
  1768.   switch (Msg)
  1769.   {
  1770.     case WM_INITDIALOG: 
  1771.       {
  1772.         SetDlgItemText (hDlg, IDC_FIREWALLHOST, szFireWallHost);
  1773.         SetDlgItemText (hDlg, IDC_FIREWALLUSER, szFireWallUserID);
  1774.         SetDlgItemText (hDlg, IDC_FIREWALLPASS, szFireWallUserPass);
  1775.       } break;
  1776.     case WM_CLOSE     : PostMessage (hDlg, WM_COMMAND, IDCANCEL, 0L); break;
  1777.     case WM_COMMAND   : switch (wParam)
  1778.       {
  1779.         case IDOK     : GetDlgItemText (hDlg, IDC_FIREWALLHOST, szFireWallHost, 80);
  1780.                         GetDlgItemText (hDlg, IDC_FIREWALLUSER, szFireWallUserID, 25);
  1781.                         GetDlgItemText (hDlg, IDC_FIREWALLPASS, szFireWallUserPass, 25);
  1782.                         EndDialog(hDlg, TRUE); return TRUE;
  1783.         case IDCANCEL : EndDialog(hDlg, FALSE); return TRUE;
  1784.         default       : return TRUE;
  1785.       }
  1786.     default: return FALSE;
  1787.   }
  1788. }
  1789.  
  1790. //*****************************************************************************
  1791. //*****************************************************************************
  1792. BOOL CALLBACK WS_InputMsgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
  1793.   switch(Msg)
  1794.   {
  1795.     case WM_INITDIALOG: SetDlgItemText (hDlg, DLG_PROMPT, szDlgPrompt);
  1796.                         SetDlgItemText (hDlg, DLG_EDIT, szDlgEdit);
  1797.                         cwCenter (hDlg, 0);
  1798.                         break;
  1799.     //case WM_CLOSE     : PostMessage (hDlg, WM_COMMAND, IDCANCEL, 0L); break;
  1800.     case WM_COMMAND   : switch (wParam)
  1801.       {
  1802.         case IDOK     : GetDlgItemText (hDlg, DLG_EDIT, szDlgEdit, 70);
  1803.                         EndDialog (hDlg, TRUE);
  1804.                         break;
  1805.         case IDCANCEL : EndDialog (hDlg, FALSE);
  1806.                         break;
  1807.       } break;
  1808.       
  1809.     default: return FALSE;
  1810.   }
  1811.   return TRUE;
  1812. }
  1813.  
  1814. //*****************************************************************************
  1815. //*****************************************************************************
  1816. BOOL CALLBACK WS_DeleteFileProc (HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
  1817.   switch(Msg)
  1818.   {
  1819.     case WM_INITDIALOG: SetDlgItemText (hDlg, DLG_EDIT, szDlgEdit); break;
  1820.     //case WM_CLOSE     : PostMessage (hDlg, WM_COMMAND, IDCANCEL, 0L); break;
  1821.     case WM_COMMAND   : switch (wParam)
  1822.       {
  1823.         case DLG_NOTDELETE: EndDialog (hDlg, DLG_NOTDELETE); break;
  1824.         case DLG_DELETEALL: EndDialog (hDlg, DLG_DELETEALL); break;
  1825.         case DLG_DELETE   : EndDialog (hDlg, DLG_DELETE); break;
  1826.         case IDCANCEL     : EndDialog (hDlg, IDCANCEL);   break;
  1827.       } break;
  1828.       
  1829.     default: return FALSE;
  1830.   }
  1831.   return TRUE;
  1832. }
  1833.  
  1834. static int nViewer=0;
  1835.  
  1836. //*****************************************************************************
  1837. //*****************************************************************************
  1838. void GetViewerInfo (HWND hDlg)
  1839. {
  1840.   char szExt[10], szPgm[80], szDir[80];
  1841.   LPSTR lp1, lp2, lp3;
  1842.   int nI, nTyp, nXfer;
  1843.   
  1844.   GetDlgItemText (hDlg, DLG_VIEWTYPE, szExt, 5);
  1845.   GetDlgItemText (hDlg, DLG_VIEWPGM,  szPgm, 75);
  1846.   GetDlgItemText (hDlg, DLG_VIEWDIR,  szDir, 75);
  1847.   strupr (szExt);
  1848.   
  1849.   nTyp = IsDlgButtonChecked (hDlg, DLG_VIEW_ASCII) ? TYPE_A : TYPE_I;
  1850.   lp1 = lpVuExt (nViewer);
  1851.   lp2 = lpVuPgm (nViewer);
  1852.   lp3 = lpVuDir (nViewer);
  1853.   
  1854.   nXfer = GetViewTyp (nViewer);
  1855.   if ((lstrcmp (lp1, szExt)==0)&&(lstrcmp (lp2, szPgm)==0)&&
  1856.       (lstrcmp (lp3, szDir)==0)&&(nXfer==nTyp)) return;
  1857.  
  1858.   for (nI=0; nI<nViewNum; nI++)
  1859.   {
  1860.     if (lstrcmp (lpVuExt (nI), szExt)==0)
  1861.     {
  1862.       lstrcpy (lpVuPgm (nI), szPgm);
  1863.       lstrcpy (lpVuDir (nI), szDir);
  1864.       SetViewTyp (nI, (char) nTyp);
  1865.       return;
  1866.     }
  1867.   }
  1868.   if (ReAllocViewer (nViewNum+1)!=NULL)
  1869.   {
  1870.     nI = nViewNum++;
  1871.     lstrcpy (lpVuExt (nI), szExt);
  1872.     lstrcpy (lpVuPgm (nI), szPgm);
  1873.     lstrcpy (lpVuDir (nI), szDir);
  1874.     SetViewTyp (nI, (char) nTyp);
  1875.   }
  1876. }
  1877.  
  1878. //*****************************************************************************
  1879. //*****************************************************************************
  1880. void SetViewerInfo (HWND hDlg, int nBtn)
  1881. {
  1882.   int nTyp;
  1883.   HWND hWndScroll = GetDlgItem (hDlg, DLG_SCROLLVIEWER);
  1884.         
  1885.   SetDlgItemText (hDlg, DLG_VIEWTYPE, lpVuExt (nBtn));
  1886.   SetDlgItemText (hDlg, DLG_VIEWPGM,  lpVuPgm (nBtn));
  1887.   SetDlgItemText (hDlg, DLG_VIEWDIR,  lpVuDir (nBtn));
  1888.   nTyp = GetViewTyp (nBtn);
  1889.   CheckDlgButton (hDlg, DLG_VIEW_ASCII, nTyp==TYPE_A);
  1890.   CheckDlgButton (hDlg, DLG_VIEW_BINARY, nTyp==TYPE_I);
  1891.   SetScrollRange (hWndScroll, SB_CTL, 0, nViewNum-1, FALSE);
  1892.   SetScrollPos (hWndScroll, SB_CTL, nBtn, TRUE);
  1893. }
  1894.  
  1895. //*****************************************************************************
  1896. //*****************************************************************************
  1897. BOOL CALLBACK WS_StatMsgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
  1898.   switch(Msg)
  1899.   {
  1900.     case WM_INITDIALOG: switch (fType)
  1901.       {
  1902.         case TYPE_A : CheckRadioButton(hDlg,RB_ASCII,RB_L8,RB_ASCII); break;
  1903.         case TYPE_I : CheckRadioButton(hDlg,RB_ASCII,RB_L8,RB_BINARY); break;
  1904.         default     : CheckRadioButton(hDlg,RB_ASCII,RB_L8,RB_L8); break;
  1905.       }
  1906.       SetDlgItemText (hDlg, DLG_EDIT, szViewer);
  1907.       SetDlgItemText (hDlg, DLG_MAILADDR, szMailAddress);
  1908.       SetDlgItemText (hDlg, DLG_TEMPDIR,  szTempDir);
  1909.       
  1910.       CheckDlgButton(hDlg, DLG_DBLCLK_VIEW, bDblClkVu);
  1911.       CheckDlgButton(hDlg, DLG_DBLCLK_XFER, !bDblClkVu);
  1912.  
  1913.       if (nViewNum>0) SetViewerInfo (hDlg, nViewer=0);
  1914.       
  1915.       CheckDlgButton(hDlg, CKB_VERBOSE,     bVerbose);
  1916.       CheckDlgButton(hDlg, CKB_BELL,        bBell);
  1917.       CheckDlgButton(hDlg, CKB_GLOBBING,    bDoGlob);
  1918.       CheckDlgButton(hDlg, CKB_HASH,        bHash);
  1919.       CheckDlgButton(hDlg, CKB_PROMPT,      bInteractive);
  1920.       CheckDlgButton(hDlg, CKB_MCASE,       bMCase);
  1921.       CheckDlgButton(hDlg, CKB_PORT_CMDS,   bSendPort);
  1922.       CheckDlgButton(hDlg, CKB_RECV_UNIQUE, bRecvUniq);
  1923.       CheckDlgButton(hDlg, CKB_STOR_UNIQUE, bStorUniq);
  1924.       CheckDlgButton(hDlg, CKB_CRSTRIP,     bCRstrip);
  1925.       CheckDlgButton(hDlg, CKB_AUTOSTART,   bAutoStart);
  1926.       CheckDlgButton(hDlg, CKB_RETAINFILES, bRetain);
  1927.       CheckDlgButton(hDlg, CKB_DEBUGLOG,    bDebugLog);
  1928.       break;
  1929.  
  1930.     case WM_CLOSE: PostMessage (hDlg, WM_COMMAND, IDCANCEL, 0L);
  1931.                    break;
  1932.  
  1933.     case WM_SETCURSOR: if (bCmdInProgress) SetCursor (hWaitCursor);
  1934.                        else return FALSE;
  1935.                        break;
  1936.  
  1937.     case WM_VSCROLL: 
  1938.     {
  1939. #ifdef WIN32
  1940.       HWND hCtl = (HWND) lParam;
  1941. #else
  1942.       HWND hCtl = (HWND) HIWORD (lParam);
  1943. #endif
  1944.                        
  1945.       if (hCtl != GetDlgItem (hDlg, DLG_SCROLLVIEWER)) return FALSE;
  1946.       GetViewerInfo (hDlg);
  1947.       switch (wParam)
  1948.       {
  1949.         case SB_LINEUP  : if (nViewer>0) nViewer--; break;
  1950.         case SB_LINEDOWN: if (nViewer<(nViewNum-1)) nViewer++; break;
  1951.         default         : return FALSE;
  1952.       }
  1953.       SetViewerInfo (hDlg, nViewer);
  1954.       return TRUE;
  1955.     }
  1956.                        
  1957.     case WM_COMMAND: switch(wParam)
  1958.       {
  1959.         case IDOK:  fType = TYPE_L;
  1960.                     if (IsDlgButtonChecked (hDlg, RB_ASCII)) fType = TYPE_A;
  1961.                     else if (IsDlgButtonChecked (hDlg, RB_BINARY)) fType = TYPE_I;
  1962.                     bDblClkVu   = IsDlgButtonChecked (hDlg, DLG_DBLCLK_VIEW);
  1963.                     bVerbose    = IsDlgButtonChecked (hDlg, CKB_VERBOSE);
  1964.                     bBell       = IsDlgButtonChecked (hDlg, CKB_BELL);
  1965.                     bDoGlob     = IsDlgButtonChecked (hDlg, CKB_GLOBBING);
  1966.                     bHash       = IsDlgButtonChecked (hDlg, CKB_HASH);
  1967.                     bInteractive= IsDlgButtonChecked (hDlg, CKB_PROMPT);
  1968.                     bMCase      = IsDlgButtonChecked (hDlg, CKB_MCASE);
  1969.                     bSendPort   = IsDlgButtonChecked (hDlg, CKB_PORT_CMDS);
  1970.                     bCRstrip    = IsDlgButtonChecked (hDlg, CKB_CRSTRIP);
  1971.                     bRecvUniq   = IsDlgButtonChecked (hDlg, CKB_RECV_UNIQUE);
  1972.                     bStorUniq   = IsDlgButtonChecked (hDlg, CKB_STOR_UNIQUE);
  1973.                     bAutoStart  = IsDlgButtonChecked (hDlg, CKB_AUTOSTART);
  1974.                     bRetain     = IsDlgButtonChecked (hDlg, CKB_RETAINFILES);
  1975.                     bDebugLog   = IsDlgButtonChecked (hDlg, CKB_DEBUGLOG);
  1976.                     GetDlgItemText (hDlg, DLG_EDIT, szViewer, 70);
  1977.                     GetDlgItemText (hDlg, DLG_MAILADDR, szMailAddress, 127);
  1978.                     GetDlgItemText (hDlg, DLG_TEMPDIR,  szTempDir, 70);
  1979.                     GetViewerInfo  (hDlg);
  1980.                     CreateTempFileNames (szTempDir);
  1981.                     EndDialog (hDlg, TRUE);
  1982.                     break;
  1983.  
  1984.         case IDCANCEL: EndDialog(hDlg, FALSE); break;
  1985.       }  return TRUE;
  1986.  
  1987.     default: return FALSE;
  1988.   }
  1989.   return TRUE;
  1990. }
  1991.  
  1992. #ifdef WIN32
  1993. #define  WINFTPICON   "winftpnt"
  1994. #else
  1995. #define  WINFTPICON   "winftp"
  1996. #endif
  1997.  
  1998. /************************************************************************/
  1999. /* nCwRegisterClasses Function                                          */
  2000. /* The following function registers all the classes of all the windows  */
  2001. /* associated with this application. The function returns an error code */
  2002. /* if unsuccessful, otherwise it returns 0.                             */
  2003. /************************************************************************/
  2004. int nCwRegisterClasses(void)
  2005. {
  2006.   WNDCLASS   wc;    // struct to define a window class
  2007.  
  2008.   memset(&wc, 0x00, sizeof(wc));
  2009.   wc.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNWINDOW;
  2010.   wc.lpfnWndProc = WndProc;
  2011.   wc.cbClsExtra = 0;
  2012.   wc.cbWndExtra = 0;
  2013.   wc.hInstance = hInst;
  2014.   wc.hIcon = LoadIcon (hInst, WINFTPICON);
  2015.   wc.hCursor = LoadCursor ((HINSTANCE) NULL, IDC_ARROW);
  2016.   wc.hbrBackground = hbrGray1;
  2017.   wc.lpszMenuName = "WINFTP";   /* Menu Name is App Name */
  2018.   wc.lpszClassName = szAppName; /* Class Name is App Name */
  2019.   if (RegisterClass (&wc)==0) return -1;
  2020.  
  2021.   wc.style = CS_HREDRAW | CS_VREDRAW;
  2022.   wc.lpfnWndProc   = WndXferProc;
  2023.   wc.hIcon         = LoadIcon (hInst, WINFTPICON);
  2024.   wc.hbrBackground = hbrGray1;
  2025.   wc.lpszMenuName  = NULL;      /* Menu Name is App Name */
  2026.   wc.lpszClassName = szXferWnd; /* Class Name is App Name */
  2027.   if (RegisterClass (&wc)==0) return -1;
  2028.  
  2029.   wc.style = CS_HREDRAW | CS_VREDRAW;
  2030.   wc.lpfnWndProc   = WndMsgProc;
  2031.   wc.hIcon         = LoadIcon ((HINSTANCE) NULL, IDI_ASTERISK);
  2032.   wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  2033.   wc.lpszMenuName  = NULL;      /* Menu Name is App Name */
  2034.   wc.lpszClassName = szMsgWnd; /* Class Name is App Name */
  2035.   if (RegisterClass (&wc)==0) return -1;
  2036.   return 0;
  2037. }
  2038.  
  2039. /************************************************************************/
  2040. /*  cwCenter Function                                                   */
  2041. /*  centers a window based on the client area of its parent             */
  2042. /************************************************************************/
  2043. void cwCenter(HWND hWnd, int top)
  2044. {
  2045.   POINT      pt;
  2046.   RECT       swp;
  2047.   RECT       rParent;
  2048.   int        iwidth;
  2049.   int        iheight;
  2050.  
  2051.   // get the rectangles for the parent and the child
  2052.   GetWindowRect (hWnd, &swp);
  2053.   GetClientRect (hWndMain, &rParent);
  2054.  
  2055.   // calculate the height and width for MoveWindow
  2056.   iwidth = swp.right - swp.left;
  2057.   iheight = swp.bottom - swp.top;
  2058.  
  2059.   // find the center point and convert to screen coordinates
  2060.   pt.x = (rParent.right - rParent.left) / 2;
  2061.   pt.y = (rParent.bottom - rParent.top) / 2;
  2062.   ClientToScreen (hWndMain, &pt);
  2063.  
  2064.   // calculate the new x, y starting point
  2065.   pt.x = pt.x - (iwidth / 2);
  2066.   pt.y = pt.y - (iheight / 2);
  2067.  
  2068.   // top will adjust the window position, up or down
  2069.   if (top) pt.y = pt.y + top;
  2070.  
  2071.   // move the window
  2072.   MoveWindow(hWnd, pt.x, pt.y, iwidth, iheight, FALSE);
  2073. }
  2074.  
  2075. /************************************************************************/
  2076. /*  CwUnRegisterClasses Function                                        */
  2077. /*  Deletes any refrences to windows resources created for this         */
  2078. /*  application, frees memory, deletes instance, handles and does       */
  2079. /*  clean up prior to exiting the window                                */
  2080. /************************************************************************/
  2081. void CwUnRegisterClasses (void)
  2082. {
  2083.   WNDCLASS   wc;    // struct to define a window class
  2084.   
  2085.   memset (&wc, 0x00, sizeof(wc));
  2086.   UnregisterClass (szAppName, hInst);
  2087.   UnregisterClass (szXferWnd, hInst);
  2088. }
  2089.  
  2090. //******************************************************************************
  2091. //******************************************************************************
  2092. LRESULT CALLBACK LocalDirProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  2093. {
  2094.   if (msg==WM_KEYDOWN && wParam==VK_RETURN)
  2095. #ifdef WIN32
  2096.      SendMessage (hWndMain, WM_COMMAND, MAKEWPARAM (EDT_LFILETYPE, EN_TEXTCHANGE), MAKELPARAM (hwnd, 0));
  2097. #else
  2098.      SendMessage (hWndMain, WM_COMMAND, EDT_LFILETYPE, MAKELONG (hwnd, EN_TEXTCHANGE));
  2099. #endif
  2100.   return CallWindowProc (lpfnOldLocal, hwnd, msg, wParam, lParam);
  2101. }
  2102.  
  2103. //******************************************************************************
  2104. //******************************************************************************
  2105. LRESULT CALLBACK RemoteDirProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  2106. {
  2107.   if (msg==WM_KEYDOWN && wParam==VK_RETURN)
  2108. #ifdef WIN32
  2109.      SendMessage (hWndMain, WM_COMMAND, MAKEWPARAM (EDT_RFILETYPE, EN_TEXTCHANGE), MAKELPARAM (hwnd, 0));
  2110. #else
  2111.      SendMessage (hWndMain, WM_COMMAND, EDT_RFILETYPE, MAKELONG (hwnd, EN_TEXTCHANGE));
  2112. #endif
  2113.   return CallWindowProc (lpfnOldRemote, hwnd, msg, wParam, lParam);
  2114. }
  2115.  
  2116.